re PR tree-optimization/22117 (VRP thinks <ptr type> + <ptr type> is always nonnull.)
authorKazu Hirata <kazu@codesourcery.com>
Thu, 23 Jun 2005 16:04:09 +0000 (16:04 +0000)
committerKazu Hirata <kazu@gcc.gnu.org>
Thu, 23 Jun 2005 16:04:09 +0000 (16:04 +0000)
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

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/pr22117.c [new file with mode: 0644]
gcc/tree-vrp.c

index c7aaa16eee6d2545b9ca69e5e4bea5d1fffc0780..cbf721b77fb4198226e0ba1511f593ec26071b00 100644 (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
index 9c421cb946be6308d540704df210986a42b6ff59..6250859ac8bb838e47b07634fe415058e50606fb 100644 (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
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr22117.c b/gcc/testsuite/gcc.dg/tree-ssa/pr22117.c
new file mode 100644 (file)
index 0000000..0955c45
--- /dev/null
@@ -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" } } */
index 81b0c0a471e57668ea74c6d5454e667f8a801177..284208b16924132cb82f123b4837f193abb17277 100644 (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