Bug 43833 - false warning: array subscript is above array bounds with -O3
Summary: false warning: array subscript is above array bounds with -O3
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: ---
Assignee: Jie Zhang
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-04-21 14:09 UTC by Jie Zhang
Modified: 2012-04-18 16:21 UTC (History)
2 users (show)

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 Jie Zhang 2010-04-21 14:09:51 UTC
$ cat t.c
extern unsigned char data[5];

unsigned char
foo (char *str)
{
  int i, j;
  unsigned char c = 0;

  for (i = 0; i < 8; i++)
    {
      j = i * 5;
      if ((j % 8) > 3)
        c |= data[(j / 8) + 1];
    }
  return c;
}

$ gcc t.c -O3 -Wall -c
t.c: In function ‘foo’:
t.c:13:11: warning: array subscript is above array bounds
Comment 1 Jie Zhang 2010-04-21 14:48:26 UTC
The patch:

http://gcc.gnu.org/ml/gcc-patches/2010-04/msg01304.html
Comment 2 Jie Zhang 2010-04-23 07:23:22 UTC
Updated patch

http://gcc.gnu.org/ml/gcc-patches/2010-04/msg01386.html
Comment 3 Jie Zhang 2010-04-26 10:59:54 UTC
Subject: Bug 43833

Author: jiez
Date: Mon Apr 26 10:59:34 2010
New Revision: 158727

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=158727
Log:
	PR tree-optimization/43833
	* tree-vrp.c (range_int_cst_p): New.
	(range_int_cst_singleton_p): New.
	(extract_range_from_binary_expr): Optimize BIT_AND_EXPR case
	when both operands are constants.  Use range_int_cst_p in
	BIT_IOR_EXPR case.

	testsuite/
	PR tree-optimization/43833
	gcc.dg/Warray-bounds-8.c: New test case.

Added:
    trunk/gcc/testsuite/gcc.dg/Warray-bounds-8.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-vrp.c

Comment 4 Jie Zhang 2010-04-26 11:00:08 UTC
Subject: Bug 43833

Author: jiez
Date: Mon Apr 26 10:59:48 2010
New Revision: 158728

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=158728
Log:
	PR tree-optimization/43833
	* tree-vrp.c (range_int_cst_p): New.
	(range_int_cst_singleton_p): New.
	(extract_range_from_binary_expr): Optimize BIT_AND_EXPR case
	when both operands are constants.  Use range_int_cst_p in
	BIT_IOR_EXPR case.

	testsuite/
	PR tree-optimization/43833
	gcc.dg/Warray-bounds-8.c: New test case.

Added:
    branches/gcc-4_5-branch/gcc/testsuite/gcc.dg/Warray-bounds-8.c
Modified:
    branches/gcc-4_5-branch/gcc/ChangeLog
    branches/gcc-4_5-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_5-branch/gcc/tree-vrp.c

Comment 5 Manuel López-Ibáñez 2012-04-18 16:21:36 UTC
Seems fixed. Closing.