From 5e3e35755672796445b82b03a868755d2753a02e Mon Sep 17 00:00:00 2001 From: kazu Date: Thu, 23 Jun 2005 16:04:09 +0000 Subject: 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@101272 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 6 ++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/tree-ssa/pr22117.c | 23 +++++++++++++++++++++++ gcc/tree-vrp.c | 9 ++++++++- 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr22117.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c7aaa16eee6..cbf721b77fb 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2005-06-23 Kazu Hirata + + 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 PR c++/19317 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9c421cb946b..6250859ac8b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2005-06-23 Kazu Hirata + + PR tree-optimization/22117 + * gcc.dg/tree-ssa/pr22117.c: New. + 2005-06-23 James A. Morrison PR testsuite/22123 diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr22117.c b/gcc/testsuite/gcc.dg/tree-ssa/pr22117.c new file mode 100644 index 00000000000..0955c4519fb --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr22117.c @@ -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" } } */ diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index 81b0c0a471e..284208b1692 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -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 -- cgit v1.2.1