summaryrefslogtreecommitdiffstats
path: root/src/include/assert.h
diff options
context:
space:
mode:
authorSimon Rettberg2024-04-12 14:00:15 +0200
committerSimon Rettberg2024-04-12 14:00:15 +0200
commit98dc341428e247141f120d05fac48c4e144a4c0f (patch)
tree3ebacb37927e338383ac64c2e20eb0b2f820cb85 /src/include/assert.h
parentMerge branch 'master' into openslx (diff)
parentMerge branch 'ipxe:master' into aqc1xx (diff)
downloadipxe-98dc341428e247141f120d05fac48c4e144a4c0f.tar.gz
ipxe-98dc341428e247141f120d05fac48c4e144a4c0f.tar.xz
ipxe-98dc341428e247141f120d05fac48c4e144a4c0f.zip
Merge branch 'aqc1xx' into openslx
Diffstat (limited to 'src/include/assert.h')
-rw-r--r--src/include/assert.h30
1 files changed, 21 insertions, 9 deletions
diff --git a/src/include/assert.h b/src/include/assert.h
index dd71fa71..01a28785 100644
--- a/src/include/assert.h
+++ b/src/include/assert.h
@@ -56,19 +56,31 @@ assert_printf ( const char *fmt, ... ) asm ( "printf" );
} while ( 0 )
/**
- * Assert a condition at link-time.
+ * Assert a condition at build time
*
- * If the condition is not true, the link will fail with an unresolved
- * symbol (error_symbol).
+ * If the compiler cannot prove that the condition is true, the build
+ * will fail with an error message.
+ */
+#undef static_assert
+#define static_assert(x) _Static_assert( x, #x )
+
+/**
+ * Assert a condition at build time (after dead code elimination)
+ *
+ * If the compiler cannot prove that the condition is true, the build
+ * will fail with an error message.
*
* This macro is iPXE-specific. Do not use this macro in code
* intended to be portable.
- *
*/
-#define linker_assert( condition, error_symbol ) \
- if ( ! (condition) ) { \
- extern void error_symbol ( void ); \
- error_symbol(); \
- }
+#define build_assert( condition ) \
+ do { \
+ if ( ! (condition) ) { \
+ extern void __attribute__ (( warning ( \
+ "build_assert(" #condition ") failed" \
+ ) )) _C2 ( build_assert_, __LINE__ ) ( void ); \
+ _C2 ( build_assert_, __LINE__ ) (); \
+ } \
+ } while ( 0 )
#endif /* _ASSERT_H */