]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUILD: checks: shut up yet another stupid gcc warning
authorWilly Tarreau <w@1wt.eu>
Mon, 4 Sep 2023 14:46:01 +0000 (16:46 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 4 Sep 2023 17:38:51 +0000 (19:38 +0200)
gcc has always had hallucinations regarding value ranges, and this one
is interesting, and affects branches 4.7 to 11.3 at least. When building
without threads, the randomly picked new_tid that is reduced to a multiply
by 1 shifted right 32 bits, hence a constant output of 0 shows this
warning:

  src/check.c: In function 'process_chk_conn':
  src/check.c:1150:32: warning: array subscript [-1, 0] is outside array bounds of 'struct thread_ctx[1]' [-Warray-bounds]
  In file included from include/haproxy/thread.h:28,
                   from include/haproxy/list.h:26,
                   from include/haproxy/action.h:28,
                   from src/check.c:31:

or this one when trying to force the test to see that it cannot be zero(!):

  src/check.c: In function 'process_chk_conn':
  src/check.c:1150:54: warning: array subscript [0, 0] is outside array bounds of 'struct thread_ctx[1]' [-Warray-bounds]
   1150 |         uint t2_act  = _HA_ATOMIC_LOAD(&ha_thread_ctx[thr2].active_checks);
        |                                         ~~~~~~~~~~~~~^~~~~~
  include/haproxy/atomic.h:66:40: note: in definition of macro 'HA_ATOMIC_LOAD'
     66 | #define HA_ATOMIC_LOAD(val)          *(val)
        |                                        ^~~
  src/check.c:1150:24: note: in expansion of macro '_HA_ATOMIC_LOAD'
   1150 |         uint t2_act  = _HA_ATOMIC_LOAD(&ha_thread_ctx[thr2].active_checks);
        |                        ^~~~~~~~~~~~~~~

Let's just add an ALREADY_CHECKED() statement there, no other check seems
to get rid of it. No backport is needed.

src/check.c

index 86af008747ff78d13e2fecfbe4a9361b58c31d28..652a8a5c0927b97a77d5cd47420899d646d91031 100644 (file)
@@ -1212,6 +1212,8 @@ struct task *process_chk_conn(struct task *t, void *context, unsigned int state)
                                if (new_tid == tid)
                                        continue;
 
+                               ALREADY_CHECKED(new_tid);
+
                                if (check_thread_cmp_active(tid, new_tid) > 0 &&
                                    (run_checks >= global.tune.max_checks_per_thread ||
                                     check_thread_cmp_load(tid, new_tid) > 0)) {