re PR tree-optimization/22117 (VRP thinks <ptr type> + <ptr type> is always nonnull.)

gcc/
	PR tree-optimization/22117
	* tree-vrp.c (extract_range_from_binary_expr): Compute a
	correct range when adding two pointers.

testsuite/
	PR tree-optimization/22117
	* gcc.dg/tree-ssa/pr22117.c: New.

From-SVN: r101272
This commit is contained in:
Kazu Hirata 2005-06-23 16:04:09 +00:00 committed by Kazu Hirata
parent a31de5014b
commit e57f2b4144
4 changed files with 42 additions and 1 deletions

View File

@ -1,3 +1,9 @@
2005-06-23 Kazu Hirata <kazu@codesourcery.com>
PR tree-optimization/22117
* tree-vrp.c (extract_range_from_binary_expr): Compute a
correct range when adding two pointers.
2005-06-23 Jason Merrill <jason@redhat.com>
PR c++/19317

View File

@ -1,3 +1,8 @@
2005-06-23 Kazu Hirata <kazu@codesourcery.com>
PR tree-optimization/22117
* gcc.dg/tree-ssa/pr22117.c: New.
2005-06-23 James A. Morrison <phython@gcc.gnu.org>
PR testsuite/22123

View File

@ -0,0 +1,23 @@
/* PR tree-optimization/22117
VRP used think that &p[q] is nonzero even though p and q are both
known to be zero after entering the first two "if" statements. */
/* { dg-do compile } */
/* { dg-options "-O2 -fdump-tree-vrp" } */
void
foo (int *p, int q)
{
if (p == 0)
{
if (q == 0)
{
int *r = &p[q];
if (r != 0)
link_error ();
}
}
}
/* { dg-final { scan-tree-dump-times "Folding predicate r_.* != 0B to 0" 1 "vrp" } } */
/* { dg-final { cleanup-tree-dump "vrp" } } */

View File

@ -1073,7 +1073,14 @@ extract_range_from_binary_expr (value_range_t *vr, tree expr)
ivopts is generating expressions with pointer multiplication
in them. */
if (code == PLUS_EXPR)
set_value_range_to_nonnull (vr, TREE_TYPE (expr));
{
if (range_is_nonnull (&vr0) || range_is_nonnull (&vr1))
set_value_range_to_nonnull (vr, TREE_TYPE (expr));
else if (range_is_null (&vr0) && range_is_null (&vr1))
set_value_range_to_null (vr, TREE_TYPE (expr));
else
set_value_range_to_varying (vr);
}
else
{
/* Subtracting from a pointer, may yield 0, so just drop the