[Intel-gfx] [PATCH] drm/i915: Use BUILD_BUG if possible in the i915 WARN_ON

Jani Nikula jani.nikula at linux.intel.com
Thu Dec 11 00:11:59 PST 2014


On Wed, 10 Dec 2014, Daniel Vetter <daniel.vetter at ffwll.ch> wrote:
> Faster feedback to errors is always better. This is inspired by the
> addition to WARN_ONs to mask/enable helpers for registers to make sure
> callers have the arguments ordered correctly: Pretty much always the
> arguments are static.
>
> We use WARN_ON(1) a lot in default switch statements though where we
> should always handle all cases. So add a new macro specifically for
> that.
>
> The idea to use __builtin_constant_p is from Chris Wilson.
>
> v2: Use the ({}) gcc-ism to avoid the static inline, suggested by
> Dave. My first attempt used __cond as the temp var, which is the same
> used by BUILD_BUG_ON, but with inverted sense. Hilarity ensued, so
> sprinkle i915 into the name.
>
> Also use a temporary variable to only evaluate the condition once,
> suggested by Damien.
>
> v3: It's crazy but apparently 32bit gcc can't compile out the
> BUILD_BUG_ON in a lot of cases and just falls over. I have no idea
> why, but until clue grows just disable this nifty idea on 32bit
> builds. Reported by 0-day builder.
>
> v4: Got it all wrong, apparently its the gcc version. We need 4.9+.
> Now reported by Imre.
>
> v5: Chris suggested to add the case to MISSING_CASE for speedier
> debug.

Still fails here. :(

$ gcc --version
gcc (Debian 4.9.1-19) 4.9.1

$ make
  CHK     include/config/kernel.release
  CHK     include/generated/uapi/linux/version.h
  CHK     include/generated/utsrelease.h
  CALL    scripts/checksyscalls.sh
  CHK     include/generated/compile.h
  CHK     kernel/config_data.h
  CC [M]  drivers/gpu/drm/i915/i915_drv.o
In file included from include/linux/ioport.h:12:0,
                 from include/linux/device.h:16,
                 from drivers/gpu/drm/i915/i915_drv.c:30:
drivers/gpu/drm/i915/i915_drv.c: In function ‘intel_detect_pch’:
include/linux/compiler.h:363:38: error: call to ‘__compiletime_assert_477’ declared with attribute error: BUILD_BUG_ON failed: __i915_warn_cond
  _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
                                      ^
include/linux/compiler.h:346:4: note: in definition of macro ‘__compiletime_assert’
    prefix ## suffix();    \
    ^
include/linux/compiler.h:363:2: note: in expansion of macro ‘_compiletime_assert’
  _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
  ^
include/linux/bug.h:50:37: note: in expansion of macro ‘compiletime_assert’
 #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                     ^
include/linux/bug.h:74:2: note: in expansion of macro ‘BUILD_BUG_ON_MSG’
  BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
  ^
drivers/gpu/drm/i915/i915_drv.h:66:3: note: in expansion of macro ‘BUILD_BUG_ON’
   BUILD_BUG_ON(__i915_warn_cond); \
   ^
drivers/gpu/drm/i915/i915_drv.c:477:5: note: in expansion of macro ‘WARN_ON’
     WARN_ON(!IS_HSW_ULT(dev));
     ^
include/linux/compiler.h:363:38: error: call to ‘__compiletime_assert_456’ declared with attribute error: BUILD_BUG_ON failed: __i915_warn_cond
  _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
                                      ^
include/linux/compiler.h:346:4: note: in definition of macro ‘__compiletime_assert’
    prefix ## suffix();    \
    ^
include/linux/compiler.h:363:2: note: in expansion of macro ‘_compiletime_assert’
  _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
  ^
include/linux/bug.h:50:37: note: in expansion of macro ‘compiletime_assert’
 #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                     ^
include/linux/bug.h:74:2: note: in expansion of macro ‘BUILD_BUG_ON_MSG’
  BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
  ^
drivers/gpu/drm/i915/i915_drv.h:66:3: note: in expansion of macro ‘BUILD_BUG_ON’
   BUILD_BUG_ON(__i915_warn_cond); \
   ^
drivers/gpu/drm/i915/i915_drv.c:456:5: note: in expansion of macro ‘WARN_ON’
     WARN_ON(!(IS_GEN6(dev) || IS_IVYBRIDGE(dev)));
     ^
include/linux/compiler.h:363:38: error: call to ‘__compiletime_assert_461’ declared with attribute error: BUILD_BUG_ON failed: __i915_warn_cond
  _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
                                      ^
include/linux/compiler.h:346:4: note: in definition of macro ‘__compiletime_assert’
    prefix ## suffix();    \
    ^
include/linux/compiler.h:363:2: note: in expansion of macro ‘_compiletime_assert’
  _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
  ^
include/linux/bug.h:50:37: note: in expansion of macro ‘compiletime_assert’
 #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                     ^
include/linux/bug.h:74:2: note: in expansion of macro ‘BUILD_BUG_ON_MSG’
  BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
  ^
drivers/gpu/drm/i915/i915_drv.h:66:3: note: in expansion of macro ‘BUILD_BUG_ON’
   BUILD_BUG_ON(__i915_warn_cond); \
   ^
drivers/gpu/drm/i915/i915_drv.c:461:5: note: in expansion of macro ‘WARN_ON’
     WARN_ON(!(IS_GEN6(dev) || IS_IVYBRIDGE(dev)));
     ^
include/linux/compiler.h:363:38: error: call to ‘__compiletime_assert_466’ declared with attribute error: BUILD_BUG_ON failed: __i915_warn_cond
  _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
                                      ^
include/linux/compiler.h:346:4: note: in definition of macro ‘__compiletime_assert’
    prefix ## suffix();    \
    ^
include/linux/compiler.h:363:2: note: in expansion of macro ‘_compiletime_assert’
  _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
  ^
include/linux/bug.h:50:37: note: in expansion of macro ‘compiletime_assert’
 #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                     ^
include/linux/bug.h:74:2: note: in expansion of macro ‘BUILD_BUG_ON_MSG’
  BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
  ^
drivers/gpu/drm/i915/i915_drv.h:66:3: note: in expansion of macro ‘BUILD_BUG_ON’
   BUILD_BUG_ON(__i915_warn_cond); \
   ^
drivers/gpu/drm/i915/i915_drv.c:466:5: note: in expansion of macro ‘WARN_ON’
     WARN_ON(IS_HSW_ULT(dev));
     ^
scripts/Makefile.build:257: recipe for target 'drivers/gpu/drm/i915/i915_drv.o' failed
make[4]: *** [drivers/gpu/drm/i915/i915_drv.o] Error 1
scripts/Makefile.build:402: recipe for target 'drivers/gpu/drm/i915' failed
make[3]: *** [drivers/gpu/drm/i915] Error 2
scripts/Makefile.build:402: recipe for target 'drivers/gpu/drm' failed
make[2]: *** [drivers/gpu/drm] Error 2
scripts/Makefile.build:402: recipe for target 'drivers/gpu' failed
make[1]: *** [drivers/gpu] Error 2
Makefile:937: recipe for target 'drivers' failed
make: *** [drivers] Error 2


-- 
Jani Nikula, Intel Open Source Technology Center


More information about the Intel-gfx mailing list