From: Willy Tarreau Date: Mon, 9 Dec 2024 16:49:08 +0000 (+0100) Subject: BUILD: debug: fix build issues in COUNT_IF() with -Wunused-value X-Git-Tag: v3.2-dev1~22 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d6dc8120c0b13f896bf2628e611517701aff7a38;p=thirdparty%2Fhaproxy.git BUILD: debug: fix build issues in COUNT_IF() with -Wunused-value Commit 7f64bb79fd ("BUG/MINOR: debug: COUNT_IF() should return true/false") allowed the COUNT_IF() macro to return the evaluated value. This is handy to place it in "if ()" conditions and count them at the same time. When glitches are disabled, the condition is just returned as-is, but most call places do not use the result, making some compilers complain. In addition, while reviewing this, it was noticed that when DEBUG_STRICT=0, the macro would still be replaced by a "do { } while (0)" statement, which not only does not evaluate the expression, but also cannot return anything. Ditto for COUNT_IF_HOT(). Let's make sure both are always properly evaluated now. --- diff --git a/include/haproxy/bug.h b/include/haproxy/bug.h index 51317d2209..1cf4333461 100644 --- a/include/haproxy/bug.h +++ b/include/haproxy/bug.h @@ -245,7 +245,7 @@ extern __attribute__((__weak__)) struct debug_count __stop_dbg_cnt HA_SECTION_S #else /* USE_OBSOLETE_LINKER not defined below */ # define __DBG_COUNT(cond, file, line, type, ...) do { } while (0) -# define _COUNT_IF(cond, file, line, ...) (cond) +# define _COUNT_IF(cond, file, line, ...) DISGUISE(cond) # define _COUNT_GLITCH(file, line, ...) do { } while (0) #endif @@ -351,7 +351,7 @@ extern __attribute__((__weak__)) struct debug_count __stop_dbg_cnt HA_SECTION_S # 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) -# define COUNT_IF(cond, ...) do { (void)sizeof(cond); } while (0) +# define COUNT_IF(cond, ...) DISGUISE(cond) #endif /* These macros are only for hot paths and remain disabled unless DEBUG_STRICT is 2 or above. @@ -378,7 +378,7 @@ extern __attribute__((__weak__)) struct debug_count __stop_dbg_cnt HA_SECTION_S #else # define BUG_ON_HOT(cond, ...) do { (void)sizeof(cond) ; } while (0) # define CHECK_IF_HOT(cond, ...) do { (void)sizeof(cond) ; } while (0) -# define COUNT_IF_HOT(cond, ...) do { (void)sizeof(cond) ; } while (0) +# define COUNT_IF_HOT(cond, ...) DISGUISE(cond) #endif