@@ -534,17 +534,22 @@ function any_stmt_may_throw(ir::IRCode, bb::Int)
534534 return false
535535end
536536
537- function conditional_successors_may_throw ( lazypostdomtree:: LazyPostDomtree , ir:: IRCode , bb:: Int )
537+ function visit_conditional_successors (callback, lazypostdomtree:: LazyPostDomtree , ir:: IRCode , bb:: Int )
538538 visited = BitSet ((bb,))
539539 worklist = Int[bb]
540540 while ! isempty (worklist)
541- thisbb = pop ! (worklist)
541+ thisbb = popfirst ! (worklist)
542542 for succ in ir. cfg. blocks[thisbb]. succs
543543 succ in visited && continue
544544 push! (visited, succ)
545- postdominates (get! (lazypostdomtree), succ, thisbb) && continue
546- any_stmt_may_throw (ir, succ) && return true
547- push! (worklist, succ)
545+ if postdominates (get! (lazypostdomtree), succ, bb)
546+ # this successor is not conditional, so no need to visit it further
547+ continue
548+ elseif callback (succ)
549+ return true
550+ else
551+ push! (worklist, succ)
552+ end
548553 end
549554 end
550555 return false
@@ -836,8 +841,10 @@ function ((; sv)::ScanStmt)(inst::Instruction, lstmt::Int, bb::Int)
836841 # inconsistent region.
837842 if ! sv. result. ipo_effects. terminates
838843 sv. all_retpaths_consistent = false
839- elseif conditional_successors_may_throw (sv. lazypostdomtree, sv. ir, bb)
840- # Check if there are potential throws that require
844+ elseif visit_conditional_successors (sv. lazypostdomtree, sv. ir, bb) do succ:: Int
845+ return any_stmt_may_throw (sv. ir, succ)
846+ end
847+ # check if this `GotoIfNot` leads to conditional throws, which taints consistency
841848 sv. all_retpaths_consistent = false
842849 else
843850 (; cfg, domtree) = get! (sv. lazyagdomtree)
0 commit comments