GCC and out-of-range constant array indexes?
Gary Funck
gary@intrepid.com
Fri Oct 8 20:39:00 GMT 2010
On 10/08/10 13:22:46, Ian Lance Taylor wrote:
> I think both of those alternatives would be surprising and easily
> misunderstood behaviour for many compiler users. [...]
I find the following behavior to be surprising:
$ gcc -Warray-bounds -O0 -c t.c
$ gcc -Warray-bounds -O1 -c t.c
$ gcc -Warray-bounds -O2 -c t.c
t.c: In function âmainâ:
t.c:6: warning: array subscript is above array bounds
t.c:7: warning: array subscript is below array bounds
The impact is that I may think that after I build my project at
-O0 or -O1, with various warnings enabled, that there are
potential surprises that await, when I perform a production build
at -O2 and higher.
It makes perfect sense to me that the following happens:
$ gcc -Warray-bounds -O1 -c t.c
t.c: Warning: -Warray-bounds has no effect unless compiled
with optimization level -O2 and higher.
> Almost all current warnings already meet those requirements; the main
> problem child is -Wuninitialized.
... and -Warray-bounds?
More information about the Gcc
mailing list