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:

> Consider the following:
>
> $ cat -n t.c
>      1
>      2  int A[10] = { 0 };
>      3
>      4  int main()
>      5  {
>      6    A[10] = 10;
>      7    A[-1] = -1;
>      8    return 0;
>      9  }
>
> In a compiler test case that I reviewed recently, there was the
> expectation that the compiler would issue a compile-time warning
> on the statements at lines 6 an 7 above.  I tried this with
> GCC version "gcc (GCC) 4.4.4 20100630 (Red Hat 4.4.4-10)"
> recently and was unable to find compilation switches that
> would cause it to complain about the use of out-of-range
> indexes above.

-Warray-bounds, but that is one of the warnings which is unfortunately
only available when optimizing.  In this case it requires -O2.

There was an attempt a couple of years ago to implement this warning
when not optimizing, but it leds to http://gcc.gnu.org/PR36108 , where
the issue is that there are array bounds violations which occur in code
which is never executed.  When not optimizing, the compiler does not
currently know which code is executed and which is not.

Ian


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