https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99474
Bug ID: 99474
Summary: missing warning on an out of bounds VLA access by a
pointer
Product: gcc
Version: 11.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: ---
The out of bounds access in both functions below should be diagnosed by
-Warray-bounds but only the first one is.
$ cat v.c && gcc -O2 -S -Wall v.c
void f (void*);
void g (void)
{
int a[5];
int *p = &a[0];
p[5] = 0; // -Warray-bounds (good)
f (a);
}
void h (int n)
{
if (n > 5)
n = 5;
int a[n];
int *p = &a[0];
p[5] = 0; // missing warning
f (a);
}
v.c: In function ‘g’:
v.c:7:4: warning: array subscript 5 is outside array bounds of ‘int[5]’
[-Warray-bounds]
7 | p[5] = 0; // -Warray-bounds (good)
| ~^~~
v.c:5:7: note: while referencing ‘a’
5 | int a[5];
| ^