[Bug tree-optimization/86223] New: missing -Warray-bounds on an access to an implicitly zeroed out array
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Jun 19 22:11:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86223
Bug ID: 86223
Summary: missing -Warray-bounds on an access to an implicitly
zeroed out array
Product: gcc
Version: 8.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: ---
When both bounds of an array index are out of range, GCC diagnoses the use of
the index to refer beyond the bounds of a local array whose elements have all
been explicitly initialized, but it fails to diagnose the same out-of-bounds
access when the array has not been fully initialized.
$ cat d.c && gcc -O2 -S -Wall d.c
void f (int);
void g (unsigned i)
{
if (i < 5 || 123 < i)
i = 5;
int a[3] = { 0 };
f (a[i]); // missing -Warray-bounds
}
void h (unsigned i)
{
if (i < 5 || 123 < i)
i = 5;
int a[3] = { 0, 0, 0 };
f (a[i]); // -Warray-bounds (good)
}
d.c: In function ‘h’:
d.c:18:3: warning: array subscript 5 is above array bounds of ‘int[3]’
[-Warray-bounds]
f (a[i]); // -Warray-bounds (good)
^~~~~~~~
More information about the Gcc-bugs
mailing list