https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82612
Bug ID: 82612
Summary: missing -Warray-bounds on a non-zero offset from the
address of a non-array object
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: ---
More testing of my -Warray-bounds patch for pr82588 et al. exposed a missing
warning on the following corner case (and similar cases like it).
$ cat a.c && gcc -O2 -S -Warray-bounds a.c
int g (int i)
{
int *p = &i;
return p[2];
}
To detect this the implementation could check the operand of the address-of
operator and trigger if it's a non-array object. It should even be possible to
detect the out-of-bounds index in the following:
int a[3];
int b[5];
int f (int i)
{
int *p = i < 0 ? a : b;
return p[7];
}