Re: False positive from -Warray-bounds?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Vincent Lefevre <vincent+gcc@xxxxxxxxxx> writes:

> On 2011-12-29 15:24:08 -0800, Ian Lance Taylor wrote:
>> I guess it's a matter of perspective.  What that text is intended to say
>> is: the compiler can prove that the array access is out of bounds.
>
> ... based on an incorrect hypothesis (that the path can be reached).
> With an incorrect hypothesis, one can prove anything.

This is not logic.  It is compiler optimization.


> So, I don't
> think that would be a valid proof.
>
> For instance, compiling the following code with -O2 -Warray-bounds -c
> triggers the warning.
>
> unsigned int f(unsigned int value)
> {
>   unsigned int i = (value & 0xffff);
>   return (i == 0xffff ? 0xffffffff : i);
> }
>
> static int arr1[10];
>
> void t(unsigned int s)
> {
>   if (s >> 1 == 0)
>     {
>       arr1[f(s)] = 0;
>       arr1[f(s)] = 0;
>     }
> }

To me this only proves that the compiler is not smart enough to see that
(s >> 1 == 0) implies that ((s & 0xffff) == 0xffff) can not be true.

Are you suggesting that the compiler should never warn if there is a
conditional guarding the array access?  Would that in practice be better
or worse than the current behaviour?

Ian


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux