[Bug c/35587] -Warray-bounds does not work at all or does not find all trivial cases, and :works only with -O2 or -O3
rguenth at gcc dot gnu dot org
gcc-bugzilla@gcc.gnu.org
Mon Mar 17 14:06:00 GMT 2008
------- Comment #3 from rguenth at gcc dot gnu dot org 2008-03-17 14:05 -------
Hm, with gcc 4.2 I get
gcc-4.2 -c t.c -O2 -Wall
t.c: In function 'main':
t.c:5: warning: array subscript is below array bounds
t.c:7: warning: array subscript is above array bounds
t.c:8: warning: array subscript is above array bounds
t.c:9: warning: array subscript is above array bounds
(the warning in line 11 is missing as the constant is
propagated and the load from a[15] CSEd - this is a very hard
to fix implementation limit. You'd fix the case in line 9
and then the issue in line 11 would pop up.)
with 4.3 I indeed see
gcc-4.3 -c t.c -O2 -Wall
(nothing)
because all invalid stores are deleted from the code and the only
used value (a[15]) is propagated from the store a[15] = 0 and thus
replaced by the constant 0. Again a hard to fix implementation
issue - after all these invalid stores/loads invoke undefined
behavior which is why we just "optimized" them.
IMHO for these very simple cases the frontend should already warn
(even at -O0 and -O1) and not rely on the code surviving until VRP.
(The issue is that we in this way would also warn in dead code regions,
which may be a problem on its own).
Note this is not accepts-invalid as it is only undefined at runtime.
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mueller at gcc dot gnu dot
| |org, rguenth at gcc dot gnu
| |dot org
Severity|major |enhancement
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Keywords|accepts-invalid |
Last reconfirmed|0000-00-00 00:00:00 |2008-03-17 14:05:57
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35587
More information about the Gcc-bugs
mailing list