This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/65461] -Warray-bounds warnings in the linux kernel (free_area_init_nodes)
- From: "slash.tmp at free dot fr" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 18 Oct 2017 10:53:24 +0000
- Subject: [Bug tree-optimization/65461] -Warray-bounds warnings in the linux kernel (free_area_init_nodes)
- Auto-submitted: auto-generated
- References: <bug-65461-4@http.gcc.gnu.org/bugzilla/>
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