DCE preserves stmts performing abnormal control flow transfer but
currently has an exception for replaceable allocations and cxa_atexit
calls. That results in a broken CFG since DCE isn't set up to prune
abnormal edges possibly hanging off those.
While we could try to add this handling, the following is the safe
fix at this point and more suitable for backporting.
PR tree-optimization/118973
* tree-ssa-dce.cc (mark_stmt_if_obviously_necessary): Calls
that alter control flow in unpredictable ways need to be
preserved.
* g++.dg/torture/pr118973.C: New testcase.
--- /dev/null
+// { dg-do compile }
+
+int foo() __attribute__((returns_twice));
+
+void a()
+{
+ int a;
+ if(foo()) new int;
+ &a;
+}
{
gcall *call = as_a <gcall *> (stmt);
- /* Never elide a noreturn call we pruned control-flow for. */
- if ((gimple_call_flags (call) & ECF_NORETURN)
- && gimple_call_ctrl_altering_p (call))
+ /* Never elide a noreturn call we pruned control-flow for.
+ Same for statements that can alter control flow in unpredictable
+ ways. */
+ if (gimple_call_ctrl_altering_p (call))
{
mark_stmt_necessary (call, true);
return;
}
-
if (is_removable_allocation_p (call, false))
return;