aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMartin Jambor <mjambor@suse.cz>2025-01-29 10:51:08 +0100
committerMartin Jambor <jamborm@gcc.gnu.org>2025-01-29 10:51:34 +0100
commit3d07e7bf13d4aec794dd25b5090c139b4d78283d (patch)
treefbcf38a6e77160dd9d3a1bac67a0bc7c24c50dcf /gcc
parent5a48079c15fda4863b02eb253e473c57a5105528 (diff)
downloadgcc-3d07e7bf13d4aec794dd25b5090c139b4d78283d.zip
gcc-3d07e7bf13d4aec794dd25b5090c139b4d78283d.tar.gz
gcc-3d07e7bf13d4aec794dd25b5090c139b4d78283d.tar.bz2
tree-ssa-dce: Avoid creating invalid BBs with no outgoing edge (PR117892)
Zhendong Su and Michal Jireš found out that our gimple DSE pass can, under fairly specific conditions, remove a noreturn call which then leaves behind a "normal" BB with no successor edges which following passes do not expect. This patch simply tells the pass to leave such calls alone even when they otherwise appear to be dead. Interestingly, our CFG verifier does not report this. I'll put on my todo list to add a test for it in the next stage 1. gcc/ChangeLog: 2025-01-28 Martin Jambor <mjambor@suse.cz> PR tree-optimization/117892 * tree-ssa-dse.cc (dse_optimize_call): Leave control-altering noreturn calls alone. gcc/testsuite/ChangeLog: 2025-01-27 Martin Jambor <mjambor@suse.cz> PR tree-optimization/117892 * gcc.dg/tree-ssa/pr117892.c: New test. * gcc.dg/tree-ssa/pr118517.c: Likewise. co-authored-by: Michal Jireš <mjires@suse.cz>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/pr117892.c17
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/pr118517.c11
-rw-r--r--gcc/tree-ssa-dse.cc6
3 files changed, 32 insertions, 2 deletions
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr117892.c b/gcc/testsuite/gcc.dg/tree-ssa/pr117892.c
new file mode 100644
index 0000000..d9b9c15
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr117892.c
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-O1" } */
+
+
+volatile int a;
+void b(int *c) {
+ int *d = 0;
+ *c = 0;
+ *d = 0;
+ __builtin_abort();
+}
+int main() {
+ int f;
+ if (a)
+ b(&f);
+ return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr118517.c b/gcc/testsuite/gcc.dg/tree-ssa/pr118517.c
new file mode 100644
index 0000000..3a34f67
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr118517.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O1 -fno-ipa-pure-const" } */
+
+void __attribute__((noreturn)) bar(void) {
+ __builtin_unreachable ();
+}
+
+int p;
+void foo() {
+ if (p) bar();
+}
diff --git a/gcc/tree-ssa-dse.cc b/gcc/tree-ssa-dse.cc
index 753d7ef..bc632e3 100644
--- a/gcc/tree-ssa-dse.cc
+++ b/gcc/tree-ssa-dse.cc
@@ -1396,8 +1396,10 @@ dse_optimize_call (gimple_stmt_iterator *gsi, sbitmap live_bytes)
if (!node)
return false;
- if (stmt_could_throw_p (cfun, stmt)
- && !cfun->can_delete_dead_exceptions)
+ if ((stmt_could_throw_p (cfun, stmt)
+ && !cfun->can_delete_dead_exceptions)
+ || ((gimple_call_flags (stmt) & ECF_NORETURN)
+ && gimple_call_ctrl_altering_p (stmt)))
return false;
/* If return value is used the call is not dead. */