https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65461
Mason <slash.tmp at free dot fr> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |msebor at gcc dot gnu.org, | |slash.tmp at free dot fr --- Comment #3 from Mason <slash.tmp at free dot fr> --- Here is a reduced test case: extern void foo(int *p); extern int array[2]; void func(void) { int i; for (i = 1; i < 2; i++) { if (i == 1) continue; array[i-1] = 0; } foo(&i); } $ gcc-7 -O3 -Wall -S testcase5.c testcase5.c: In function 'func': testcase5.c:9:14: warning: array subscript is below array bounds [-Warray-bounds] array[i-1] = 0; ~~~~~^~~~~ It is obvious that the loop is a NOP (other than setting i to 2) (start at 1, skip that index, move to 2, exit loop) And gcc figures it out, but only after issuing a spurious warning. func: subq $24, %rsp # allocate space on the stack leaq 12(%rsp), %rdi # copy &i to rdi movl $2, 12(%rsp) # i = 2 call foo # foo(&i) addq $24, %rsp # clean up stack ret