https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61277
Bug ID: 61277
Summary: Incorrect -Warray-bounds warning with 4.9.0
Product: gcc
Version: 4.9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: akruppa at gmail dot com
The following code, when compiled with the gcc 4.9.0 release or with SVN branch
gcc-4_9-branch r210719, via
gcc -O2 -Wall -c bug.c
produces the warning
bug.c: In function ‘foo’:
bug.c:13:8: warning: array subscript is below array bounds [-Warray-bounds]
if (s[n-1] != 2)
^
If foo() returns 2, the array accesses are not out of bounds.
Gcc 4.8.1 does not produce the warning.
The gcc 4.9.0 and SVN builds were configured with
configure --prefix=install/dir/ --enable-languages=c,c++
int foo();
int s[2];
int bar()
{
int n = foo();
int i;
for(i = 0 ; i < n ; i++)
if ((i == 0) != (s[i] == 0))
return 0;
if (s[n-1] != 2)
return 0;
for(i = 0 ; i < n ; i++)
if (s[0])
return 0;
return 1;
}