From: Richard Guenther Date: Mon, 4 Jul 2011 13:25:21 +0000 (+0000) Subject: backport: re PR tree-optimization/49115 (invalid return value optimization (?) when... X-Git-Tag: releases/gcc-4.5.4~557 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=69d2b841467f404658e05d6ebfabda1628f21811;p=thirdparty%2Fgcc.git backport: re PR tree-optimization/49115 (invalid return value optimization (?) when exception is thrown and caught) 2011-07-04 Richard Guenther Backport from mainline 2011-05-23 Richard Guenther PR tree-optimization/49115 * tree-ssa-dce.c (mark_aliased_reaching_defs_necessary_1): Likewise. * g++.dg/torture/pr49115.C: New testcase. From-SVN: r175812 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 4bd7435ec8f6..440ce2a85af0 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2011-07-04 Richard Guenther + + Backport from mainline + 2011-05-23 Richard Guenther + + PR tree-optimization/49115 + * tree-ssa-dce.c (mark_aliased_reaching_defs_necessary_1): Likewise. + 2011-07-04 Richard Guenther PR tree-optimization/49615 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a88b2f23b770..babb1fc487ac 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2011-07-04 Richard Guenther + + Backport from mainline + 2011-05-23 Richard Guenther + + PR tree-optimization/49115 + * g++.dg/torture/pr49115.C: New testcase. + 2011-07-04 Richard Guenther PR tree-optimization/49615 diff --git a/gcc/testsuite/g++.dg/torture/pr49115.C b/gcc/testsuite/g++.dg/torture/pr49115.C new file mode 100644 index 000000000000..c4cce21ba5d9 --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr49115.C @@ -0,0 +1,25 @@ +// { dg-do run } + +extern "C" void abort (void); +struct MyException {}; +struct Data { + int nr; + Data() : nr(66) {} +}; +Data __attribute__((noinline,noclone)) getData(int i) +{ + if (i) throw MyException(); + Data data; + data.nr = i; + return data; +} +int main(int, char **) +{ + Data data; + try { + data = getData(1); + } catch (MyException& e) { + if (data.nr != 66) + abort (); + } +} diff --git a/gcc/tree-ssa-dce.c b/gcc/tree-ssa-dce.c index f0e8a34f4cfa..220f8c49aae3 100644 --- a/gcc/tree-ssa-dce.c +++ b/gcc/tree-ssa-dce.c @@ -509,7 +509,14 @@ mark_aliased_reaching_defs_necessary_1 (ao_ref *ref, tree vdef, void *data) /* If the stmt lhs kills ref, then we can stop walking. */ if (gimple_has_lhs (def_stmt) - && TREE_CODE (gimple_get_lhs (def_stmt)) != SSA_NAME) + && TREE_CODE (gimple_get_lhs (def_stmt)) != SSA_NAME + /* The assignment is not necessarily carried out if it can throw + and we can catch it in the current function where we could inspect + the previous value. + ??? We only need to care about the RHS throwing. For aggregate + assignments or similar calls and non-call exceptions the LHS + might throw as well. */ + && !stmt_can_throw_internal (def_stmt)) { tree base, lhs = gimple_get_lhs (def_stmt); HOST_WIDE_INT size, offset, max_size;