Bug 69595 - [6 Regression] Bogus -Warray-bound warning due to missed optimization
Summary: [6 Regression] Bogus -Warray-bound warning due to missed optimization
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 6.0
: P3 normal
Target Milestone: 6.0
Assignee: Richard Biener
URL:
Keywords: diagnostic, missed-optimization
Depends on:
Blocks:
 
Reported: 2016-02-01 14:58 UTC by Richard Biener
Modified: 2016-02-15 13:50 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2016-02-01 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2016-02-01 14:58:09 UTC
char *y;
void foo (int sysnum)
{
  static char *x[] = {};
  int nsyscalls = sizeof x / sizeof x[0];
  if (sysnum < 0 || sysnum >= nsyscalls)
    return;
  else
    y = x[sysnum];
}

warns at -O2 -Warray-bounds because we don't optimize sysnum < 0 || sysnum >= 0 to true before VRP1.  We optimize this only in reassoc.

VRP warns as 'sysnum' in the x[sysnum] path is UNDEFINED.
Comment 1 Richard Biener 2016-02-01 15:17:31 UTC
So VRP doesn't detect the block is unreachable:

_6 = sysnum_4(D) < 0;
Found new range for _6: [0, +INF]
interesting_ssa_edges: adding SSA use in _8 = _6 | _7;
marking stmt to be not simulated again

Visiting statement:
_7 = sysnum_4(D) >= 0;
Found new range for _7: [0, +INF]
marking stmt to be not simulated again

Visiting statement:
_8 = _6 | _7;
Applying pattern match.pd:796, gimple-match.c:164
Found new range for _8: [0, +INF]
interesting_ssa_edges: adding SSA use in if (_8 != 0)

the old issue having to decide between using an integer range or a symbolic
range for a non-assert range we derive (as equivalences are keyed to specific
SSA names and we only have one here, _6).
Comment 2 Richard Biener 2016-02-01 15:33:16 UTC
We want to improve extract_range_from_comparison to build a symbolic range instead of varying here.
Comment 3 Richard Biener 2016-02-02 15:20:05 UTC
Author: rguenth
Date: Tue Feb  2 15:19:32 2016
New Revision: 233076

URL: https://gcc.gnu.org/viewcvs?rev=233076&root=gcc&view=rev
Log:
2016-02-02  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/69595
	* match.pd: Add range test simplifications to true/false.

	* gcc.dg/Warray-bounds-17.c: New testcase.

Added:
    trunk/gcc/testsuite/gcc.dg/Warray-bounds-17.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/match.pd
    trunk/gcc/testsuite/ChangeLog
Comment 4 Richard Biener 2016-02-02 15:26:37 UTC
Fixed.
Comment 5 Richard Biener 2016-02-15 13:50:14 UTC
Author: rguenth
Date: Mon Feb 15 13:49:42 2016
New Revision: 233425

URL: https://gcc.gnu.org/viewcvs?rev=233425&root=gcc&view=rev
Log:
2016-02-15  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/69595
	* match.pd: Complete range test simplification to true.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/match.pd