Skip to content

Commit da9f934

Browse files
authored
fix compute_trycatch for IRCode /w EnterNode with catch_dest==0 (#56846)
1 parent 17857ca commit da9f934

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Compiler/src/inferencestate.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ function (::ComputeTryCatch{Handler})(code::Vector{Any}, bbs::Union{Vector{Basic
475475
(;handlers, handler_at) = handler_info =
476476
(handler_info === nothing ? HandlerInfo{Handler}(Handler[], fill((0, 0), n)) : handler_info)
477477
l = stmt.catch_dest
478-
(bbs !== nothing) && (l = first(bbs[l].stmts))
478+
(bbs !== nothing) && (l != 0) && (l = first(bbs[l].stmts))
479479
push!(handlers, Handler(stmt, pc))
480480
handler_id = length(handlers)
481481
handler_at[pc + 1] = (handler_id, 0)
@@ -519,7 +519,7 @@ function (::ComputeTryCatch{Handler})(code::Vector{Any}, bbs::Union{Vector{Basic
519519
break
520520
elseif isa(stmt, EnterNode)
521521
l = stmt.catch_dest
522-
(bbs !== nothing) && (l = first(bbs[l].stmts))
522+
(bbs !== nothing) && (l != 0) && (l = first(bbs[l].stmts))
523523
# We assigned a handler number above. Here we just merge that
524524
# with out current handler information.
525525
if l != 0

Compiler/test/irpasses.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,6 +1716,12 @@ end
17161716
@test scope_folding_opt() == 1
17171717
@test_broken fully_eliminated(scope_folding)
17181718
@test_broken fully_eliminated(scope_folding_opt)
1719+
let ir = first(only(Base.code_ircode(scope_folding, ())))
1720+
@test Compiler.compute_trycatch(ir) isa Compiler.HandlerInfo
1721+
end
1722+
let ir = first(only(Base.code_ircode(scope_folding_opt, ())))
1723+
@test Compiler.compute_trycatch(ir) isa Compiler.HandlerInfo
1724+
end
17191725

17201726
# Function that happened to have lots of sroa that
17211727
# happened to trigger a bad case in the renamer. We

0 commit comments

Comments
 (0)