]> git.kaiwu.me - haproxy.git/commitdiff
BUILD: http: fix build of macro http_harden() with clang
authorWilly Tarreau <w@1wt.eu>
Fri, 6 Nov 2026 14:57:31 +0000 (15:57 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 6 Nov 2026 15:00:53 +0000 (16:00 +0100)
clang doesn't seem to like that COUNT_IF() returns an expression that
produces a result that is not used:

    CC      src/http_htx.o
  src/http_htx.c:2076:16: warning: expression result unused [-Wunused-value]
                  if (unlikely(http_harden(HTTP_HRD_DEL_ALL_TLR))) {
                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  include/haproxy/http.h:137:3: note: expanded from macro 'http_harden'
                  COUNT_IF(1, "hardening " #flag " condition met");             \
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  include/haproxy/bug.h:485:31: note: expanded from macro 'COUNT_IF'
  #  define COUNT_IF(cond, ...) _COUNT_IF   (cond, __FILE__, __LINE__, __VA_ARGS__)
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  include/haproxy/bug.h:388:7: note: expanded from macro '_COUNT_IF'
          }) : 0)
               ^
  include/haproxy/compiler.h:351:40: note: expanded from macro 'unlikely'
  #define unlikely(x) (__builtin_expect((x) != 0, 0))
                                         ^
  src/http_htx.c:2076:16: warning: expression result unused [-Wunused-value]
                  if (unlikely(http_harden(HTTP_HRD_DEL_ALL_TLR))) {
                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  include/haproxy/http.h:139:4: note: expanded from macro 'http_harden'
                          COUNT_IF(1, "hardening " #flag " enforced");          \
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  include/haproxy/bug.h:485:31: note: expanded from macro 'COUNT_IF'
  #  define COUNT_IF(cond, ...) _COUNT_IF   (cond, __FILE__, __LINE__, __VA_ARGS__)
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  include/haproxy/bug.h:388:7: note: expanded from macro '_COUNT_IF'
          }) : 0)
               ^
  include/haproxy/compiler.h:351:40: note: expanded from macro 'unlikely'
  #define unlikely(x) (__builtin_expect((x) != 0, 0))
                                         ^
  2 warnings generated.

Just placing a (void) in front of COUNT_IF() is sufficient to silence it.
No backport is needed, as this is only in 3.5.

include/haproxy/http.h

index 34befa5bdd5be680ca6c8df9c0c339c0f06d002b..2b2832fea5974f49f81907ee4d0a2dd1a4a49f76 100644 (file)
@@ -134,9 +134,9 @@ static inline void http_reset_hardening_check(struct http_hdng_chk *chk)
        int _ret = 0;                                                         \
        if (unlikely((http_hdng_chk.rules | ~http_hdng_chk.found) & _flag)) { \
                http_hdng_chk.found |= _flag;                                 \
-               COUNT_IF(1, "hardening " #flag " condition met");             \
+               (void)COUNT_IF(1, "hardening " #flag " condition met");       \
                if (http_hdng_chk.rules & _flag) {                            \
-                       COUNT_IF(1, "hardening " #flag " enforced");          \
+                       (void)COUNT_IF(1, "hardening " #flag " enforced");    \
                        http_hdng_chk.fixed |= _flag;                         \
                        _ret = 1;                                             \
                }                                                             \