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]) | ~~~~~~^~~~~~~~~