[Bug middle-end/92378] missing -Warray-bounds warning
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Nov 5 15:31:00 GMT 2019
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92378
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
CC| |msebor at gcc dot gnu.org
Component|c |middle-end
Resolution|--- |DUPLICATE
Assignee|unassigned at gcc dot gnu.org |msebor at gcc dot gnu.org
Target Milestone|--- |10.0
--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
The cause of the missing -Warray-bounds warning is that the SRA pass
substitutes an uninitialized scalar variable for a[3]. I'm not sure why
-Wuninitialized doesn't point to the variable, but the fix for pr92341 I'm
about to commit corrects this as well and has GCC output the following:
pr92378.c: In function ‘main’:
pr92378.c:5:5: warning: array subscript 3 is above array bounds of ‘int[1]’
[-Warray-bounds]
5 | printf("%d", a[3]);
| ^~~~~~~~~~~~~~~~~~
pr92378.c:4:9: note: while referencing ‘a’
4 | int a[1]={0};
| ^
In GCC, -Warray-bounds only runs with optimization so the bug isn't detected
otherwise even in simple cases. In a future release (maybe GCC 11) we'd like
to change it so the simple cases can be diagnosed even without optimization.
*** This bug has been marked as a duplicate of bug 92341 ***
More information about the Gcc-bugs
mailing list