Bug 67077 - [6 Regression] Incorrect "array subscript is above array bounds" warning with -O2
Summary: [6 Regression] Incorrect "array subscript is above array bounds" warning with...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 6.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-07-31 12:59 UTC by Vincent Lefèvre
Modified: 2015-08-03 16:58 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vincent Lefèvre 2015-07-31 12:59:10 UTC
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).
Comment 1 Richard Biener 2015-08-03 10:32:34 UTC
I believe this has been fixed with

2015-07-23  Richard Biener  <rguenther@suse.de>

        PR middle-end/66916
        * match.pd: Guard widen and sign-change comparison simplification
        with single_use.
Comment 2 hjl@gcc.gnu.org 2015-08-03 16:58:34 UTC
Author: hjl
Date: Mon Aug  3 16:58:03 2015
New Revision: 226518

URL: https://gcc.gnu.org/viewcvs?rev=226518&root=gcc&view=rev
Log:
Add a testcase for PR tree-optimization/67077

	PR tree-optimization/67077
	* gcc.dg/pr67077.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/pr67077.c
Modified:
    trunk/gcc/testsuite/ChangeLog