Re: False positive from -Warray-bounds?

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

 



On 2011-12-29 14:02:23 -0800, Ian Lance Taylor wrote:
> Lars Gullik Bjønnes <larsbj@xxxxxxxxxx> writes:
> 
> > I have this code:
> >
> > --------------
> > 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)
> > {
> >     arr1[f(s)] = 0;
> >     arr1[f(s)] = 0;
> > }
> > ------------------
[...]
> The warning triggers if there is some code path in which the index is
> provably out of bounds.  That is true of this code.  I don't think I
> would describe this as a false positive.  I think it is a case where, as
> the -Wall documentation says, the code should be modified to avoid the
> warning.

The -Warray-bounds warning occurs with:

void t(unsigned int s)
{
    arr1[f(s)] = 0;
    arr1[f(s)] = 0;
}

but not with:

void t(unsigned int s)
{
    arr1[f(s)] = 0;
}

If "The warning triggers if there is some code path in which the index
is provably out of bounds." is the intended behavior (assuming that
the warning phrasing isn't really correct), isn't this proof the same
one in both cases? Why this difference in the gcc behavior?

Tested with the -O2 -Warray-bounds -c options and:
  gcc (Debian 4.6.2-9) 4.6.2
and
  gcc-snapshot (Debian 20111210-1) 4.7.0 20111210 (experimental) [trunk revision 182188]

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Arénaire project (LIP, ENS-Lyon)


[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