outof-ssa vs. -fnon-call-exceptions: known problem?

Diego Novillo dnovillo@google.com
Sun Sep 30 17:00:00 GMT 2007


On 9/29/07, Richard Sandiford <rsandifo@nildram.co.uk> wrote:
> ------------------------------------------------------------------------
> int main() ()
> {
> <bb 2>:
>   __builtin_puts (&"Foo"[0]);
>   foo (1 / 0);
>   return 0;
>
> }
> ------------------------------------------------------------------------
>
> So the unoptimised program behaves as expected, raising the divide-by-zero
> trap before printing "Foo".  The optimised version prints "Foo" first.
> Is this a known problem?  (I tried to find it in bugzilla, but couldn't)

Fixed with:

2007-09-29  Diego Novillo  <dnovillo@google.com>

        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.

Index: testsuite/g++.dg/tree-ssa/pr33593.C
===================================================================
--- testsuite/g++.dg/tree-ssa/pr33593.C (revision 0)
+++ testsuite/g++.dg/tree-ssa/pr33593.C (revision 0)
@@ -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: tree-ssa-ter.c
===================================================================
--- tree-ssa-ter.c      (revision 128885)
+++ tree-ssa-ter.c      (working copy)
@@ -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)



More information about the Gcc-patches mailing list