Skip to content

Commit

Permalink
sroa: Fix small logic bug (#52717)
Browse files Browse the repository at this point in the history
This fixes #52703, which happened when a function had a foldable,
try-catch-with-scope inside an ordinary try/catch. The fix is to simply
ignore the ordinary try/catch and treat it as a regular fallthrough
terminator.
  • Loading branch information
Keno authored Jan 3, 2024
1 parent 3a3af82 commit d97ab8a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
7 changes: 4 additions & 3 deletions base/compiler/ssair/passes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1209,10 +1209,11 @@ function sroa_pass!(ir::IRCode, inlining::Union{Nothing,InliningState}=nothing)
end
if scope_mapping !== nothing && did_just_finish_bb(compact)
bb = compact.active_result_bb - 1
if isexpr(stmt, :leave)
update_scope_mapping!(scope_mapping, bb+1, scope_mapping[block_for_inst(compact, scope_mapping[bb])])
bbs = scope_mapping[bb]
if isexpr(stmt, :leave) && bbs != SSAValue(0)
update_scope_mapping!(scope_mapping, bb+1, scope_mapping[block_for_inst(compact, bbs)])
else
update_scope_mapping!(scope_mapping, bb+1, scope_mapping[bb])
update_scope_mapping!(scope_mapping, bb+1, bbs)
end
end
# check whether this statement is `getfield` / `setfield!` (or other "interesting" statement)
Expand Down
15 changes: 15 additions & 0 deletions test/compiler/irpasses.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1725,3 +1725,18 @@ function f52610()
return nothing
end
@test code_typed(f52610)[1][2] === Nothing

# Issue #52703
@eval function f52703()
try
$(Expr(:tryfinally,
Expr(:block,
Expr(:tryfinally, :(), :(), 2),
:(return Base.inferencebarrier(Core.current_scope)()::Int)),
:(), 1))
catch
return 1
end
return 0
end
@test code_typed(f52703)[1][2] === Int

0 comments on commit d97ab8a

Please sign in to comment.