[Bug c/60121] New: gcc does not warn an obvious out-of-bound array access at -O0 and -O1
su at cs dot ucdavis.edu
gcc-bugzilla@gcc.gnu.org
Sat Feb 8 23:15:00 GMT 2014
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60121
Bug ID: 60121
Summary: gcc does not warn an obvious out-of-bound array access
at -O0 and -O1
Product: gcc
Version: 4.9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: su at cs dot ucdavis.edu
For the given testcase below, gcc doesn't warn the out-of-bound array access at
-O0 and -O1, but does at -Os and above, while clang warns at all optimization
levels. Since the out-of-bound access is obvious, I wonder whether gcc should
also warn at -O0 and -O1.
This affects the current gcc trunk and all earlier versions.
$ gcc-trunk -v
Using built-in specs.
COLLECT_GCC=gcc-trunk
COLLECT_LTO_WRAPPER=/usr/local/gcc-trunk/libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-trunk/configure --prefix=/usr/local/gcc-trunk
--enable-languages=c,c++ --disable-werror --enable-multilib
Thread model: posix
gcc version 4.9.0 20140208 (experimental) [trunk revision 207627] (GCC)
$
$ gcc-trunk -Warray-bounds -O0 small.c
$ gcc-trunk -Warray-bounds -O1 small.c
$
$ gcc-trunk -Warray-bounds -Os small.c
small.c: In function ‘main’:
small.c:8:10: warning: array subscript is above array bounds [-Warray-bounds]
if (b[613])
^
$
$ clang-trunk -Warray-bounds -O0 small.c
small.c:8:9: warning: array index 613 is past the end of the array (which
contains 1 element) [-Warray-bounds]
if (b[613])
^ ~~~
small.c:1:1: note: array 'b' declared here
int a, b[1];
^
1 warning generated.
$
More information about the Gcc-bugs
mailing list