tree-outof-ssa can move potentially-trapping operations across what were sequence points, even when compiled with -fnon-call-exceptions. E.g., consider the following C++ code, compiled with -fnon-call-exceptions: ------------------------------------------------------------------------ #include <stdio.h> void foo (int) { printf ("Bar\n"); } int main (void) { int a = 1 / 0; printf ("Foo\n"); foo (a); } ------------------------------------------------------------------------ The tree optimisers themselves preserve the intent of the code, but tree-outof-ssa.c propogates the division into the call to foo(): ------------------------------------------------------------------------ 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.
Assigning to Diego as he already has a patch (thanks!)
1 / 0; that does not aways trap. on ppc an undefined value is returned.
Subject: Re: tree-outof-ssa moves sources of non-call exceptions past sequence points On 29 Sep 2007 19:05:20 -0000, pinskia at gcc dot gnu dot org <gcc-bugzilla@gcc.gnu.org> wrote: > 1 / 0; > > that does not aways trap. on ppc an undefined value is returned. In which case tree_could_trap_p() will/should return false on this expression then.
I think 1/0 should not be marked as throwing though as it is target dependent if it actually will trap or not. In fact as I mentioned on PPC, it does not trap.
Subject: Bug 33593 Author: dnovillo Date: Sun Sep 30 16:00:36 2007 New Revision: 128893 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=128893 Log: 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. Added: trunk/gcc/testsuite/g++.dg/tree-ssa/pr33593.C Modified: trunk/gcc/ChangeLog trunk/gcc/testsuite/ChangeLog trunk/gcc/tree-ssa-ter.c
Should be fixed on the trunk.