re PR c++/23046 (ICE in set_value_range, at tree-vrp.c:191)
authorDiego Novillo <dnovillo@gcc.gnu.org>
Tue, 8 Nov 2005 21:09:51 +0000 (16:09 -0500)
committerDiego Novillo <dnovillo@gcc.gnu.org>
Tue, 8 Nov 2005 21:09:51 +0000 (16:09 -0500)
2005-11-08  James A. Morrison  <phython@gcc.gnu.org>
    Diego Novillo  <dnovillo@redhat.com>

PR 23046
* tree-vrp.c (register_edge_assert_for): Do not register
always-false predicates.

testsuite/

PR 23046
* g++.dg/tree-ssa/pr23046.C: New test.

From-SVN: r106656

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/tree-ssa/pr23046.C [new file with mode: 0644]
gcc/tree-vrp.c

index 4f792d3ecd1ec0824e97b0e8a67a78a18ea5e5b0..5d6bfe6aec639d96a3cc9f5dd0ab0b25d79bcf9c 100644 (file)
@@ -1,3 +1,10 @@
+2005-11-08  James A. Morrison  <phython@gcc.gnu.org>
+           Diego Novillo  <dnovillo@redhat.com>
+
+       PR 23046
+       * tree-vrp.c (register_edge_assert_for): Do not register
+       always-false predicates.
+
 2005-11-08  Devang Patel <dpatel@apple.com>
 
        PR tree-optimization/23115
index 6ea074165f2b3c8616eede6c1fef07d5bf35796a..644433544f26208bc9f6c6e096e79f5fa9ed1214 100644 (file)
@@ -1,3 +1,8 @@
+2005-11-08  Diego Novillo  <dnovillo@redhat.com>
+
+       PR 23046
+       * g++.dg/tree-ssa/pr23046.C: New test.
+
 2005-11-08  Devang Patel <dpatel@apple.com>
 
        PR tree-optimization/23115
diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr23046.C b/gcc/testsuite/g++.dg/tree-ssa/pr23046.C
new file mode 100644 (file)
index 0000000..eb8f395
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+enum eumtype { ENUM1, ENUM2 };
+void g(const eumtype kind );
+void f(long i);
+void g(const eumtype kind)
+{
+  if ((kind != ENUM1) && (kind != ENUM2))
+    f(kind);
+}
index 929908bf4735692ae80f48b30a0dfa6e219bc891..d49c4d40d32d4e2e5e06a7595d2d2caf3d2ebb1b 100644 (file)
@@ -2504,6 +2504,24 @@ register_edge_assert_for (tree name, edge e, block_stmt_iterator si)
             need to invert the sign comparison.  */
          if (is_else_edge)
            comp_code = invert_tree_comparison (comp_code, 0);
+
+         /* Do not register always-false predicates.  FIXME, this
+            works around a limitation in fold() when dealing with
+            enumerations.  Given 'enum { N1, N2 } x;', fold will not
+            fold 'if (x > N2)' to 'if (0)'.  */
+         if ((comp_code == GT_EXPR || comp_code == LT_EXPR)
+             && (INTEGRAL_TYPE_P (TREE_TYPE (val))
+                 || SCALAR_FLOAT_TYPE_P (TREE_TYPE (val))))
+           {
+             tree min = TYPE_MIN_VALUE (TREE_TYPE (val));
+             tree max = TYPE_MAX_VALUE (TREE_TYPE (val));
+
+             if (comp_code == GT_EXPR && compare_values (val, max) == 0)
+               return false;
+
+             if (comp_code == LT_EXPR && compare_values (val, min) == 0)
+               return false;
+           }
        }
     }
   else