This avoids fixing up a stmt we removed as part of EH cleanup
earlier during the DOM cleanup phase.

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

        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.
---
 gcc/testsuite/c-c++-common/torture/pr128172.c | 22 +++++++++++++++++++
 gcc/tree-ssa-dom.cc                           |  3 +++
 2 files changed, 25 insertions(+)
 create mode 100644 gcc/testsuite/c-c++-common/torture/pr128172.c

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 00000000000..27808177637
--- /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 27381e0a473..9c4fb474f5f 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 ");

base-commit: def63f7c26207e4dfefcf5e92c07ea2582474dc5
-- 
2.51.0

Reply via email to