]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR tree-optimization/49115 (invalid return value optimization (?) when...
authorRichard Guenther <rguenther@suse.de>
Mon, 4 Jul 2011 13:25:21 +0000 (13:25 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 4 Jul 2011 13:25:21 +0000 (13:25 +0000)
2011-07-04  Richard Guenther  <rguenther@suse.de>

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

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

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/torture/pr49115.C [new file with mode: 0644]
gcc/tree-ssa-dce.c

index 4bd7435ec8f61a21348c30fbd253b03ff6ca23d7..440ce2a85af0ed4fe0c30fb1d5325d72c1573c13 100644 (file)
@@ -1,3 +1,11 @@
+2011-07-04  Richard Guenther  <rguenther@suse.de>
+
+       Backport from mainline
+       2011-05-23  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/49115
+       * tree-ssa-dce.c (mark_aliased_reaching_defs_necessary_1): Likewise.
+
 2011-07-04  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/49615
index a88b2f23b770f5ae484564c10d6979ce3b080133..babb1fc487ac538396e1fef28a107c57033dd782 100644 (file)
@@ -1,3 +1,11 @@
+2011-07-04  Richard Guenther  <rguenther@suse.de>
+
+       Backport from mainline
+       2011-05-23  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/49115
+       * g++.dg/torture/pr49115.C: New testcase.
+
 2011-07-04  Richard Guenther  <rguenther@suse.de>
 
        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 (file)
index 0000000..c4cce21
--- /dev/null
@@ -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 ();
+  }
+}
index f0e8a34f4cfa9580372399cd3165f1c9534190da..220f8c49aae308be74c959a101d73f8ad4df52f2 100644 (file)
@@ -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;