Bug 33593 - tree-outof-ssa moves sources of non-call exceptions past sequence points
Summary: tree-outof-ssa moves sources of non-call exceptions past sequence points
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.3.0
Assignee: dnovillo@google.com
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2007-09-29 19:01 UTC by Richard Sandiford
Modified: 2008-02-03 14:35 UTC (History)
2 users (show)

See Also:
Host: x86_64-linux-gnu
Target: x86_64-linux-gnu
Build: x86_64-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Sandiford 2007-09-29 19:01:23 UTC
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.
Comment 1 Richard Sandiford 2007-09-29 19:05:00 UTC
Assigning to Diego as he already has a patch (thanks!)
Comment 2 Andrew Pinski 2007-09-29 19:05:20 UTC
1 / 0;

that does not aways trap.  on ppc an undefined value is returned.
Comment 3 dnovillo@google.com 2007-09-29 19:08:04 UTC
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.
Comment 4 Andrew Pinski 2007-09-29 19:08:35 UTC
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.
Comment 5 Diego Novillo 2007-09-30 16:00:47 UTC
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

Comment 6 Steven Bosscher 2008-02-03 14:35:21 UTC
Should be fixed on the trunk.