[Bug tree-optimization/67077] New: [6 Regression] Incorrect "array subscript is above array bounds" warning with -O2

vincent-gcc at vinc17 dot net gcc-bugzilla@gcc.gnu.org
Fri Jul 31 12:59:00 GMT 2015


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67077

            Bug ID: 67077
           Summary: [6 Regression] Incorrect "array subscript is above
                    array bounds" warning with -O2
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vincent-gcc at vinc17 dot net
  Target Milestone: ---

With Debian's gcc-snapshot 20150722-1 on the following program, I get an
incorrect warning "array subscript is above array bounds".

unsigned char buffer[8];
unsigned long foo (void)
{
  unsigned long i;
  i = buffer[0];
  if (i >= 8)
    return i - 7;
  i++;
  while (i > 8)
    {
      if (buffer[i-1] != 0)
        return 0;
      i--;
    }
  return 1;
}

zira:~> gcc-snapshot -Wall -O2 -c tst.c
tst.c: In function 'foo':
tst.c:11:17: warning: array subscript is above array bounds [-Warray-bounds]
       if (buffer[i-1] != 0)
                 ^

I don't get this warning if I use -O1 or gcc-snapshot 20150701-1 (thus this
problem is very recent) or GCC 5.1.1 (gcc-5 Debian package).

Notes:
* There are other bugs concerning this warning, but they are older, while here
this is a recent regression.
* The above code has been obtained by simplifying MPFR's
mpfr_fpif_read_precision_from_file function in fpif.c (trunk).



More information about the Gcc-bugs mailing list