public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/97429] New: missing -Warray-bounds indexing past the end of a pointer to array
@ 2020-10-14 20:41 msebor at gcc dot gnu.org
0 siblings, 0 replies; only message in thread
From: msebor at gcc dot gnu.org @ 2020-10-14 20:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97429
Bug ID: 97429
Summary: missing -Warray-bounds indexing past the end of a
pointer to array
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 index in fa(), ga(), and fp() is diagnosed as expected by
-Warray-bounds but the same bug in gp() is not. They all should be.
$ cat xx.c && gcc -O2 -S -Wall xx.c
int fa (int a[3][5])
{
return a[3][5]; // warning (good)
}
int ga (int a[3][5])
{
int *p = &a[0][0];
return p[15]; // warning (good)
}
int fp (int (*pa)[3][5])
{
return (*pa)[3][5]; // warning (good)
}
int gp (int (*pa)[3][5])
{
int *p = &(*pa)[0][0]; // missing warning
return p[15];
}
xx.c: In function ‘fa’:
xx.c:3:14: warning: array subscript 5 is above array bounds of ‘int[5]’
[-Warray-bounds]
3 | return a[3][5]; // warning (good)
| ~~~~^~~
xx.c:1:13: note: while referencing ‘a’
1 | int fa (int a[3][5])
| ~~~~^~~~~~~
xx.c: In function ‘ga’:
xx.c:9:11: warning: array subscript 15 is outside array bounds of ‘int[3]’
[-Warray-bounds]
9 | return p[15]; // warning (good)
| ~^~~~
xx.c:6:13: note: while referencing ‘a’
6 | int ga (int a[3][5])
| ~~~~^~~~~~~
xx.c: In function ‘fp’:
xx.c:15:18: warning: array subscript 5 is above array bounds of ‘int[5]’
[-Warray-bounds]
15 | return (*pa)[3][5]; // warning (good)
| ~~~~~~~~^~~
xx.c:13:15: note: while referencing ‘pa’
13 | int fp (int (*pa)[3][5])
| ~~~~~~^~~~~~~~~
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-10-14 20:41 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-14 20:41 [Bug tree-optimization/97429] New: missing -Warray-bounds indexing past the end of a pointer to array msebor at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).