summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkazu <kazu@138bc75d-0d04-0410-961f-82ee72b054a4>2005-06-23 16:04:09 +0000
committerkazu <kazu@138bc75d-0d04-0410-961f-82ee72b054a4>2005-06-23 16:04:09 +0000
commit5e3e35755672796445b82b03a868755d2753a02e (patch)
tree4a87e6c81eafd68c0f78223179ac6386a7acd539
parent5b2a414e414bfddcd554aba94dfcf4739b28d9a0 (diff)
downloadgcc-5e3e35755672796445b82b03a868755d2753a02e.tar.gz
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
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/pr22117.c23
-rw-r--r--gcc/tree-vrp.c9
4 files changed, 42 insertions, 1 deletions
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 <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
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 <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
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