]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/126150 - ICE with replace_uses_by
authorRichard Biener <rguenther@suse.de>
Wed, 8 Jul 2026 11:57:17 +0000 (13:57 +0200)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 8 Jul 2026 12:44:51 +0000 (14:44 +0200)
replace_uses_by triggers eventual BB removal from inside a
FOR_EACH_IMM_USE_STMT iteration.  That's a no-go since we might
eliminate uses in the list we are currently processing.  The
fix is to defer EH edge purging.

PR tree-optimization/126150
* tree-cfg.cc (replace_uses_by): Delay purging of EH edges
until after FOR_EACH_IMM_USE_STMT finished.

* g++.dg/pr126150.C: New testcase.

gcc/testsuite/g++.dg/pr126150.C [new file with mode: 0644]
gcc/tree-cfg.cc

diff --git a/gcc/testsuite/g++.dg/pr126150.C b/gcc/testsuite/g++.dg/pr126150.C
new file mode 100644 (file)
index 0000000..0ca5360
--- /dev/null
@@ -0,0 +1,8 @@
+// { dg-do compile }
+// { dg-options "-fnon-call-exceptions -O2 --param=max-completely-peel-loop-nest-depth=0" }
+
+struct B {
+  B() { t = 0; }
+  ~B();
+  int t;
+} w3[1][2];
index dc07dde8cfd4cfa48ea52e28e96717fb5b7958ab..15e026919461a2d0f7040dedb28fddd6b71e8ee9 100644 (file)
@@ -1893,6 +1893,7 @@ replace_uses_by (tree name, tree val)
   use_operand_p use;
   gimple *stmt;
   edge e;
+  auto_bitmap eh_cleanup_bbs;
 
   FOR_EACH_IMM_USE_STMT (stmt, imm_iter, name)
     {
@@ -1950,10 +1951,13 @@ replace_uses_by (tree name, tree val)
            }
 
          if (maybe_clean_or_replace_eh_stmt (orig_stmt, stmt))
-           gimple_purge_dead_eh_edges (gimple_bb (stmt));
+           bitmap_set_bit (eh_cleanup_bbs, gimple_bb (stmt)->index);
        }
     }
 
+  if (!bitmap_empty_p (eh_cleanup_bbs))
+    gimple_purge_all_dead_eh_edges (eh_cleanup_bbs);
+
   gcc_checking_assert (has_zero_uses (name));
 
   /* Also update the trees stored in loop structures.  */