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.
--- /dev/null
+// { 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];
use_operand_p use;
gimple *stmt;
edge e;
+ auto_bitmap eh_cleanup_bbs;
FOR_EACH_IMM_USE_STMT (stmt, imm_iter, name)
{
}
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. */