aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2025-02-24 09:45:28 +0100
committerRichard Biener <rguenth@gcc.gnu.org>2025-02-24 11:11:54 +0100
commit9e4c57f7a69d7060612c83867ecff61a719b97af (patch)
tree448c72f19528225838d817c0c8c1d6d675bac809 /gcc
parent27ebd2a55cd373542977b21631b6b0919e703733 (diff)
downloadgcc-9e4c57f7a69d7060612c83867ecff61a719b97af.zip
gcc-9e4c57f7a69d7060612c83867ecff61a719b97af.tar.gz
gcc-9e4c57f7a69d7060612c83867ecff61a719b97af.tar.bz2
tree-optimization/118973 - stray abnormal edge after DCE
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/testsuite/g++.dg/torture/pr118973.C10
-rw-r--r--gcc/tree-ssa-dce.cc8
2 files changed, 14 insertions, 4 deletions
diff --git a/gcc/testsuite/g++.dg/torture/pr118973.C b/gcc/testsuite/g++.dg/torture/pr118973.C
new file mode 100644
index 0000000..8cb9e4b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/torture/pr118973.C
@@ -0,0 +1,10 @@
+// { dg-do compile }
+
+int foo() __attribute__((returns_twice));
+
+void a()
+{
+ int a;
+ if(foo()) new int;
+ &a;
+}
diff --git a/gcc/tree-ssa-dce.cc b/gcc/tree-ssa-dce.cc
index be21a2d..18af818 100644
--- a/gcc/tree-ssa-dce.cc
+++ b/gcc/tree-ssa-dce.cc
@@ -391,15 +391,15 @@ mark_stmt_if_obviously_necessary (gimple *stmt, bool aggressive)
{
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;