drm/i915: make REG_BIT() and REG_GENMASK() work with variables
authorJani Nikula <jani.nikula@intel.com>
Fri, 24 May 2019 18:52:53 +0000 (21:52 +0300)
committerJani Nikula <jani.nikula@intel.com>
Mon, 27 May 2019 10:08:37 +0000 (13:08 +0300)
REG_BIT() and REG_GENMASK() were intended to work with both constant
expressions and otherwise, with the former having extra compile time
checks for the bit ranges. Incredibly, the result of
__builtin_constant_p() is not an integer constant expression when given
a non-constant expression, leading to errors in BUILD_BUG_ON_ZERO().

Replace __builtin_constant_p() with the __is_constexpr() magic spell.

Reported-by: Ville Syrjala <ville.syrjala@linux.intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190524185253.1088-1-jani.nikula@intel.com
drivers/gpu/drm/i915/i915_reg.h

index 49dce04dd688e6fe87a6096f8ee4fcc25da5f8e1..019c48748dc980cb284d06ca73d275ccb27acd37 100644 (file)
  */
 #define REG_BIT(__n)                                                   \
        ((u32)(BIT(__n) +                                               \
-              BUILD_BUG_ON_ZERO(__builtin_constant_p(__n) &&           \
+              BUILD_BUG_ON_ZERO(__is_constexpr(__n) &&         \
                                 ((__n) < 0 || (__n) > 31))))
 
 /**
  */
 #define REG_GENMASK(__high, __low)                                     \
        ((u32)(GENMASK(__high, __low) +                                 \
-              BUILD_BUG_ON_ZERO(__builtin_constant_p(__high) &&        \
-                                __builtin_constant_p(__low) &&         \
+              BUILD_BUG_ON_ZERO(__is_constexpr(__high) &&      \
+                                __is_constexpr(__low) &&               \
                                 ((__low) < 0 || (__high) > 31 || (__low) > (__high)))))
 
 /*