False positive from -Warray-bounds?

Vincent Lefevre vincent+gcc@vinc17.org
Fri Dec 30 00:16:00 GMT 2011

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

Vincent Lefèvre <vincent@vinc17.net> - 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)

More information about the Gcc-help mailing list