https://gcc.gnu.org/g:9b75ebb5068abcf009dd1f7f8014c3b535b9042e
commit r17-5665-g9b75ebb5068abcf009dd1f7f8014c3b535b9042e Author: Richard Biener <[email protected]> Date: Wed Oct 28 14:09:46 2026 +0100 tree-optimization/128172 - avoid fixing up removed stmt This avoids fixing up a stmt we removed as part of EH cleanup earlier during the DOM cleanup phase. PR tree-optimization/128172 * tree-ssa-dom.cc (pass_dominator::execute): Check a stmt is still in the IL before calling fixup_noreturn_call on it. * c-c++-common/torture/pr128172.c: New testcase. Diff: --- gcc/testsuite/c-c++-common/torture/pr128172.c | 22 ++++++++++++++++++++++ gcc/tree-ssa-dom.cc | 3 +++ 2 files changed, 25 insertions(+) diff --git a/gcc/testsuite/c-c++-common/torture/pr128172.c b/gcc/testsuite/c-c++-common/torture/pr128172.c new file mode 100644 index 000000000000..278081776370 --- /dev/null +++ b/gcc/testsuite/c-c++-common/torture/pr128172.c @@ -0,0 +1,22 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-fexceptions" } */ + +void abort(void); +static int cnt; +static void __attribute__((noinline)) die(void) { cnt++; abort(); } +typedef void (*fp_t)(void); +static void cl(fp_t *q) +{ + (*q)(); +} +void f(fp_t p) +{ + if (p != die) + return; + fp_t x __attribute__((cleanup(cl))) = p; + p(); +} +fp_t get(void) +{ + return die; +} diff --git a/gcc/tree-ssa-dom.cc b/gcc/tree-ssa-dom.cc index 27381e0a4737..9c4fb474f5fc 100644 --- a/gcc/tree-ssa-dom.cc +++ b/gcc/tree-ssa-dom.cc @@ -881,6 +881,9 @@ pass_dominator::execute (function *fun) while (!need_noreturn_fixup.is_empty ()) { gimple *stmt = need_noreturn_fixup.pop (); + /* We might have elided the stmt and its BB above. */ + if (!gimple_bb (stmt)) + continue; if (dump_file && dump_flags & TDF_DETAILS) { fprintf (dump_file, "Fixing up noreturn call ");
