This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: GCC and out-of-range constant array indexes?


Gary Funck <gary@intrepid.com> writes:

> 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.

Yes, that warning would be good for people, if it happened once.
It's like the spiel on the airplane about how to buckle your seat belt.
It's good for everybody to hear that once.  The tenth time you hear it,
it's pointless.  The hundredth time, it's annoying.

Many people compile with -Werror and most people use the same set of
warning options at all optimization levels.  So we would then require a
way to explicitly disable this warning.



>> Almost all current warnings already meet those requirements; the main
>> problem child is -Wuninitialized.
>
> ... and -Warray-bounds?

-Warray-bounds meets the criteria I listed, because it is pretty much
always a true positive.

I think you are basically suggesting that we drop the third criterion on
my list ("they should always be true positives").  I could support that
if others agree.

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]