... and use it in self-tests.h.
This is intended to replace constructs such as __bitop_bad_size(). It
produces a better diagnostic, and is MISRA-friendly.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
#define BUILD_BUG_ON(cond) ((void)BUILD_BUG_ON_ZERO(cond))
#endif
+/*
+ * Force a compilation error. This is for code which, in the normal case,
+ * should be Dead Code Eliminated, but a failure to eliminate constitutes an
+ * error. e.g. behind a __builtin_constant_p(), or an illegal case within a
+ * switch(sizeof(...)) construct.
+ */
+#define BUILD_ERROR(msg) asm ( ".error \"" msg "\"" )
+
/* Hide a value from the optimiser. */
#define HIDE(x) \
({ \
typeof((fn)(val)) real = (fn)(val); \
\
if ( !__builtin_constant_p(real) ) \
- asm ( ".error \"'" STR(fn(val)) "' not compile-time constant\"" ); \
+ BUILD_ERROR("'" STR(fn(val)) "' not compile-time constant"); \
else if ( real != (res) ) \
- asm ( ".error \"Compile time check '" STR(fn(val) == res) "' failed\"" ); \
+ BUILD_ERROR("Compile time check '" STR(fn(val) == res) "' failed"); \
} while ( 0 )
#else
#define COMPILE_CHECK(fn, val, res)