[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen staging] xen/macros: Introduce BUILD_ERROR()



commit 1b30ac12814cce506193fc39acce45b131fad8e8
Author:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
AuthorDate: Wed Jun 19 15:46:47 2024 +0100
Commit:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
CommitDate: Fri Aug 23 21:50:57 2024 +0100

    xen/macros: Introduce BUILD_ERROR()
    
    ... 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@xxxxxxxxxx>
    Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
---
 xen/include/xen/macros.h     | 8 ++++++++
 xen/include/xen/self-tests.h | 4 ++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/xen/include/xen/macros.h b/xen/include/xen/macros.h
index ec89f4654f..44d723fd12 100644
--- a/xen/include/xen/macros.h
+++ b/xen/include/xen/macros.h
@@ -59,6 +59,14 @@
 #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)                                 \
     ({                                          \
diff --git a/xen/include/xen/self-tests.h b/xen/include/xen/self-tests.h
index 58484fe5a8..e9a8794893 100644
--- a/xen/include/xen/self-tests.h
+++ b/xen/include/xen/self-tests.h
@@ -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)
--
generated by git-patchbot for /home/xen/git/xen.git#staging



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.