From fca3fc0d904296001ba2de697060f5503e7dde02 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 4 Sep 2023 16:46:01 +0200 Subject: [PATCH] BUILD: checks: shut up yet another stupid gcc warning 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 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/check.c b/src/check.c index 86af00874..652a8a5c0 100644 --- a/src/check.c +++ b/src/check.c @@ -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)) {