]> xenbits.xensource.com Git - xen.git/commitdiff
xen/macros: Introduce BUILD_ERROR()
authorAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 19 Jun 2024 14:46:47 +0000 (15:46 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 23 Aug 2024 20:50:57 +0000 (21:50 +0100)
... 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>
xen/include/xen/macros.h
xen/include/xen/self-tests.h

index ec89f4654fcf6a890022eb5f8c90eb37b6289345..44d723fd121acf799a098fb35b4c666d4aa62e4d 100644 (file)
 #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)                                 \
     ({                                          \
index 58484fe5a8ae2ac93f6be3e93f94f59867814a66..e9a879489363e29f2cbd3d1db2bb7842fdca15cd 100644 (file)
@@ -22,9 +22,9 @@
         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)