]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: debug: make BUG_ON() catch build errors even without DEBUG_STRICT
authorWilly Tarreau <w@1wt.eu>
Mon, 5 Feb 2024 14:06:05 +0000 (15:06 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 5 Feb 2024 14:09:37 +0000 (15:09 +0100)
As seen in previous commit 59acb27001 ("BUILD: quic: Variable name typo
inside a BUG_ON()."), it can sometimes happen that with DEBUG forced
without DEBUG_STRICT, BUG_ON() statements are ignored. Sadly, it means
that typos there are not even build-tested.

This patch makes these statements reference sizeof(cond) to make sure
the condition is parsed. This doesn't result in any code being emitted,
but makes sure the expression is correct so that an issue such as the one
above will fail to build (which was verified).

This may be backported as it can help spot failed backports as well.

include/haproxy/bug.h

index 54308c66c24ba1918fb9dd50c762769dff6270d0..1356acf13b09b5a55026cf497d7c851c43fcb4b2 100644 (file)
@@ -186,9 +186,9 @@ static __attribute__((noinline,noreturn,unused)) void abort_with_line(uint line)
 #  define CHECK_IF(cond)     _BUG_ON_ONCE(cond, __FILE__, __LINE__, 1, "FATAL: check ",   "")
 # endif
 #else
-#  define BUG_ON(cond)       do { } while (0)
-#  define WARN_ON(cond)      do { } while (0)
-#  define CHECK_IF(cond)     do { } while (0)
+#  define BUG_ON(cond)       do { (void)sizeof(cond); } while (0)
+#  define WARN_ON(cond)      do { (void)sizeof(cond); } while (0)
+#  define CHECK_IF(cond)     do { (void)sizeof(cond); } while (0)
 #endif
 
 /* These macros are only for hot paths and remain disabled unless DEBUG_STRICT is 2 or above.
@@ -210,8 +210,8 @@ static __attribute__((noinline,noreturn,unused)) void abort_with_line(uint line)
 #  define CHECK_IF_HOT(cond) _BUG_ON_ONCE(cond, __FILE__, __LINE__, 1, "FATAL: check ",   "")
 # endif
 #else
-#  define BUG_ON_HOT(cond)   do { } while (0)
-#  define CHECK_IF_HOT(cond) do { } while (0)
+#  define BUG_ON_HOT(cond)   do { (void)sizeof(cond); } while (0)
+#  define CHECK_IF_HOT(cond) do { (void)sizeof(cond); } while (0)
 #endif