Hi, Richard, Please ignore my previous email sent this morning. -:)
Actually, I studied more about the heuristic, and I agreed that the simplified loop as you suggested below is the correct approach to go, my current two-level nested loop is a little too complicate and confusing. > On Aug 13, 2025, at 05:24, Richard Biener <richard.guent...@gmail.com> wrote: > > So the overall CFG walk should be like > > do > { > cond_bb = get_immediate_dominator (CDI_DOMINATORS, cur_bb); > if (single_pred_p (curr_bb)) > { > auto gsi = gsi_last_bb (cond_bb); > if (!gsi_end_p (gsi) > && stmt_ends_bb_p (gsi_stmt (gsi))) > { > ... handle control stmt at the end on cond_bb ... > } > } > curr_bb = cond_bb; > } > while (depth < flag_diagnostics_show_context > && curr_bb != ENTRY_BLOCK_PTR_FOR_FN (cfun)); > > stmt_ends_bb_p is is_ctrl_stmt () || is_ctrl_altering_stmt where the > former includes GIMPLE_COND (and switch and more) and the > latter includes for example a call that internally throws. Whether > we terminate the walk upon unhandled control stmts would be > up to debate, I'd skip for now, as you do and as you also skip > GIMPLE_COND without location. > Thanks a lot for your suggestion. Qing