[Bug tree-optimization/90753] New: missing -Warray-bounds with an extern index in out-of-bounds range
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Jun 4 22:06:00 GMT 2019
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90753
Bug ID: 90753
Summary: missing -Warray-bounds with an extern index in
out-of-bounds range
Product: gcc
Version: 9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
Only the out-of-bounds access in f() below is diagnosed. The same invalid
access in g() is not. The
$ cat a.c && gcc -O2 -S -Wall -Wextra a.c
extern char a[4];
int f (int i)
{
if (i < 9 || 99 < i)
i = 9;
return a[i];
}
int g (void)
{
extern int i;
if (i < 9 || 99 < i)
i = 9;
return a[i];
}
a.c: In function ‘f’:
a.c:8:11: warning: array subscript 9 is above array bounds of ‘char[4]’
[-Warray-bounds]
8 | return a[i];
| ~^~~
a.c:1:13: note: while referencing ‘a’
1 | extern char a[4];
| ^
The VRP dump for f shows
i_4: int [9, 99]
...
<bb 4> [local count: 1073741824]:
# i_4 = PHI <9(2), i_5(D)(3)>
_3 = a[i_4];
_7 = (int) _3;
return _7;
}
while the same dump for g:
i.3_4: VARYING
...
<bb 4> [local count: 1073741824]:
i.3_4 = i;
_5 = a[i.3_4];
_9 = (int) _5;
return _9;
}
For some reason the range for the index is not available in g.
More information about the Gcc-bugs
mailing list