re PR tree-optimization/33593 (tree-outof-ssa moves sources of non-call exceptions...
authorDiego Novillo <dnovillo@google.com>
Sun, 30 Sep 2007 16:00:36 +0000 (12:00 -0400)
committerDiego Novillo <dnovillo@gcc.gnu.org>
Sun, 30 Sep 2007 16:00:36 +0000 (12:00 -0400)
PR 33593
* tree-ssa-ter.c (is_replaceable_p): Return false if STMT may
throw an exception.

testsuite/ChangeLog

PR 33593
* g++.dg/tree-ssa/pr33593.C: New test.

From-SVN: r128893

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

index ea66227391a2d93fef5fd972e2e04412cca6b360..eef9e94799bb91791ebfb1fb430fd9a2f8322eb4 100644 (file)
@@ -1,3 +1,9 @@
+2007-09-30  Diego Novillo  <dnovillo@google.com>
+
+       PR 33593
+       * tree-ssa-ter.c (is_replaceable_p): Return false if STMT may
+       throw an exception.
+
 2007-09-30  Uros Bizjak  <ubizjak@gmail.com>
 
        PR tree-optimization/33597
index 45a3afbe9de6b0d4b36a5137a1fb8a5e2a22d382..631e8a1ba7d540ce8cfed2d37e854285159bd83d 100644 (file)
@@ -1,3 +1,8 @@
+2007-09-30  Diego Novillo  <dnovillo@google.com>
+
+       PR 33593
+       * g++.dg/tree-ssa/pr33593.C: New test.
+
 2007-09-30  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
 
        PR libfortran/33400
diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr33593.C b/gcc/testsuite/g++.dg/tree-ssa/pr33593.C
new file mode 100644 (file)
index 0000000..f549740
--- /dev/null
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O1 -fnon-call-exceptions -fdump-tree-optimized" } */
+
+#include <stdio.h>
+
+void foo (int) { printf ("Bar\n"); }
+
+int
+main (void)
+{
+  int a = 1 / 0;       // { dg-warning "division by zero" }
+  printf ("Foo\n");
+  foo (a);
+}
+
+// The expression 1 / 0 should not be propagated into the call to foo() if it
+// may trap.
+// { dg-final { scan-tree-dump-times "foo \\(1 \\/ 0\\)" 0 "optimized" } }
+// { dg-final { cleanup-tree-dump "optimized" } }
index 824252e8b9f6782ed2e38c6926841e39351e22b0..f0fef24aa4a574f2bdae0cae2bea649d93cd3137 100644 (file)
@@ -366,6 +366,10 @@ is_replaceable_p (tree stmt)
   if (TREE_CODE (stmt) != GIMPLE_MODIFY_STMT)
     return false;
 
+  /* If the statement may throw an exception, it cannot be replaced.  */
+  if (tree_could_throw_p (stmt))
+    return false;
+
   /* Punt if there is more than 1 def.  */
   def = SINGLE_SSA_TREE_OPERAND (stmt, SSA_OP_DEF);
   if (!def)