]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/60750 (double free after std::move on string inside throw when compiled...
authorRichard Biener <rguenther@suse.de>
Mon, 7 Apr 2014 08:38:23 +0000 (08:38 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 7 Apr 2014 08:38:23 +0000 (08:38 +0000)
2014-04-07  Richard Biener  <rguenther@suse.de>

PR middle-end/60750
* tree-ssa-operands.c (maybe_add_call_vops): Also add VDEFs
for noreturn calls.
* tree-cfgcleanup.c (fixup_noreturn_call): Do not remove VDEFs.

* g++.dg/torture/pr60750.C: New testcase.
* gcc.dg/tree-ssa/20040517-1.c: Adjust.

From-SVN: r209179

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/torture/pr60750.C [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/20040517-1.c
gcc/tree-cfgcleanup.c
gcc/tree-ssa-operands.c

index 80a39f85ccc5323ea6f50a9b48d53ccdd3ad2f40..91ec83b058c4540e9ea95b08878e50b15cebafbd 100644 (file)
@@ -1,3 +1,10 @@
+2014-04-07  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/60750
+       * tree-ssa-operands.c (maybe_add_call_vops): Also add VDEFs
+       for noreturn calls.
+       * tree-cfgcleanup.c (fixup_noreturn_call): Do not remove VDEFs.
+
 2014-04-06  John David Anglin  <danglin@gcc.gnu.org>
 
        PR debug/55794
index 7df316ee2a28786fa1f81b0574513404c7070b49..a7c7c78cbc88018e5ff0e2d17ff0477aa2d7a4f3 100644 (file)
@@ -1,3 +1,9 @@
+2014-04-07  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/60750
+       * g++.dg/torture/pr60750.C: New testcase.
+       * gcc.dg/tree-ssa/20040517-1.c: Adjust.
+
 2014-04-06  Andreas Schwab  <schwab@linux-m68k.org>
 
        * gcc.c-torture/compile/pr60655-1.c: Use __SIZE_TYPE__ for size_t.
diff --git a/gcc/testsuite/g++.dg/torture/pr60750.C b/gcc/testsuite/g++.dg/torture/pr60750.C
new file mode 100644 (file)
index 0000000..a344bd7
--- /dev/null
@@ -0,0 +1,21 @@
+// { dg-do run }
+// { dg-options "-std=c++11" }
+
+#include <string>
+#include <stdexcept>
+
+const std::string err_prefix = "Problem: ";
+void thrower (std::string msg)
+{
+  throw std::runtime_error(err_prefix + std::move(msg));
+}
+
+int main(int argc, char **argv)
+{
+  try {
+      std::string base = "hello";
+      thrower(std::move(base));
+  } catch (const std::runtime_error &e) {
+  }
+  return 0;
+}
index 99b27ce02f1a9c35dba6e58fcd5b5d33204f665b..b49cf648c7d1fa6cb0fcaf370756a168caa8dcd7 100644 (file)
@@ -16,6 +16,7 @@ void bar (void)
 /* We used to treat malloc functions like pure and const functions, but
    malloc functions may clobber global memory.  Only the function result
    does not alias any other pointer.
-   Hence, we must have a VDEF for a before and after the call to foo().  */
-/* { dg-final { scan-tree-dump-times "VDEF" 2 "alias"} } */
+   Hence, we must have a VDEF for a before and after the call to foo().
+   And one after the call to abort().  */
+/* { dg-final { scan-tree-dump-times "VDEF" 3 "alias"} } */
 /* { dg-final { cleanup-tree-dump "alias" } } */
index 08401dd2db64d93952514ad2fc718c1931d470bd..b7882cf67625648dc70d34177483f0bff616130b 100644 (file)
@@ -586,9 +586,6 @@ fixup_noreturn_call (gimple stmt)
       update_stmt (stmt);
       changed = true;
     }
-  /* Similarly remove VDEF if there is any.  */
-  else if (gimple_vdef (stmt))
-    update_stmt (stmt);
   return changed;
 }
 
index 352ccca4e30a0b8c0531fc517d10f20ea01f4f86..c525fe579ea2108a167a74a39ddff0562e494041 100644 (file)
@@ -648,10 +648,8 @@ maybe_add_call_vops (struct function *fn, gimple stmt)
      call-clobbered.  */
   if (!(call_flags & ECF_NOVOPS))
     {
-      /* A 'pure' or a 'const' function never call-clobbers anything.
-        A 'noreturn' function might, but since we don't return anyway
-        there is no point in recording that.  */
-      if (!(call_flags & (ECF_PURE | ECF_CONST | ECF_NORETURN)))
+      /* A 'pure' or a 'const' function never call-clobbers anything.  */
+      if (!(call_flags & (ECF_PURE | ECF_CONST)))
        add_virtual_operand (fn, stmt, opf_def);
       else if (!(call_flags & ECF_CONST))
        add_virtual_operand (fn, stmt, opf_use);