Commit 094f6ab3 by Richard Guenther Committed by Richard Biener

re PR tree-optimization/49115 (invalid return value optimization (?) when…

re PR tree-optimization/49115 (invalid return value optimization (?) when exception is thrown and caught)

2011-05-23  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/49115
	* tree-ssa-alias.c (stmt_kills_ref_p_1): If the assignment
	is not necessarily carried out, do not claim it kills the ref.
	* tree-ssa-dce.c (mark_aliased_reaching_defs_necessary_1): Likewise.

	* g++.dg/torture/pr49115.C: New testcase.

From-SVN: r174066
parent 9a9822e1
2011-05-23 Richard Guenther <rguenther@suse.de> 2011-05-23 Richard Guenther <rguenther@suse.de>
PR tree-optimization/49115
* tree-ssa-alias.c (stmt_kills_ref_p_1): If the assignment
is not necessarily carried out, do not claim it kills the ref.
* tree-ssa-dce.c (mark_aliased_reaching_defs_necessary_1): Likewise.
2011-05-23 Richard Guenther <rguenther@suse.de>
PR middle-end/15419 PR middle-end/15419
* builtins.c (fold_builtin_memory_op): Be less restrictive about * builtins.c (fold_builtin_memory_op): Be less restrictive about
what pointer types we accept for folding. what pointer types we accept for folding.
......
2011-05-23 Richard Guenther <rguenther@suse.de> 2011-05-23 Richard Guenther <rguenther@suse.de>
PR tree-optimization/49115
* g++.dg/torture/pr49115.C: New testcase.
2011-05-23 Richard Guenther <rguenther@suse.de>
PR middle-end/15419 PR middle-end/15419
* gcc.dg/memcpy-3.c: New testcase. * gcc.dg/memcpy-3.c: New testcase.
......
// { 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 ();
}
}
...@@ -1633,7 +1633,14 @@ stmt_kills_ref_p_1 (gimple stmt, ao_ref *ref) ...@@ -1633,7 +1633,14 @@ stmt_kills_ref_p_1 (gimple stmt, ao_ref *ref)
return false; return false;
if (gimple_has_lhs (stmt) if (gimple_has_lhs (stmt)
&& TREE_CODE (gimple_get_lhs (stmt)) != SSA_NAME) && TREE_CODE (gimple_get_lhs (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 (stmt))
{ {
tree base, lhs = gimple_get_lhs (stmt); tree base, lhs = gimple_get_lhs (stmt);
HOST_WIDE_INT size, offset, max_size; HOST_WIDE_INT size, offset, max_size;
......
...@@ -521,7 +521,14 @@ mark_aliased_reaching_defs_necessary_1 (ao_ref *ref, tree vdef, void *data) ...@@ -521,7 +521,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 the stmt lhs kills ref, then we can stop walking. */
if (gimple_has_lhs (def_stmt) 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); tree base, lhs = gimple_get_lhs (def_stmt);
HOST_WIDE_INT size, offset, max_size; HOST_WIDE_INT size, offset, max_size;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment