https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109071
--- Comment #10 from qinzhao at gcc dot gnu.org --- with the following added heuristic in array-bound checker: + /* If the stmt is duplicated and splitted, the warning level is not 2, + and the current block is not dominating the exit block, not report + the warning. */ + if (is_splitted && warn_array_bounds < 2 + && !is_dominate_exit) + return false; + such false positive warnings are moved from -Warray-bound=1 to -Warray-bound=2. [opc@qinzhao-ol8u3-x86 109071]$ /home/opc/Install/latest-d/bin/gcc -O2 -Warray-bounds=2 -c -o t.o t.c t.c: In function ‘sparx5_set’: t.c:12:29: warning: array subscript 4 is above array bounds of ‘int[4]’ [-Warray-bounds=] 12 | int *val = &sg->vals[index]; | ~~~~~~~~^~~~~~~ t.c:8:18: note: while referencing ‘vals’ 8 | struct nums {int vals[4];}; | ^~~~ [opc@qinzhao-ol8u3-x86 109071]$ /home/opc/Install/latest-d/bin/gcc -O2 -Warray-bounds=1 -c -o t.o t.c [opc@qinzhao-ol8u3-x86 109071]$