Skip to content

Commit

Permalink
optimizer: handle EnterNode with catch_dest == 0 (#56686)
Browse files Browse the repository at this point in the history
In some parts of the optimizer code, such as `cfg_simplify!` and
irinterp, it is assumed that `EnterNode` always has `catch_dest ≠ 0`,
but this assumption is incorrect. This commit fixes those cases.
  • Loading branch information
aviatesk authored Nov 27, 2024
1 parent a17db2b commit f6ebc4b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
6 changes: 4 additions & 2 deletions Compiler/src/ssair/irinterp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,10 @@ function process_terminator!(@nospecialize(stmt), bb::Int, bb_ip::BitSetBoundedM
return backedge
elseif isa(stmt, EnterNode)
dest = stmt.catch_dest
@assert dest > bb
push!(bb_ip, dest)
if dest 0
@assert dest > bb
push!(bb_ip, dest)
end
push!(bb_ip, bb+1)
return false
else
Expand Down
6 changes: 4 additions & 2 deletions Compiler/src/ssair/passes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2393,8 +2393,10 @@ function cfg_simplify!(ir::IRCode)
end
elseif isa(terminator, EnterNode)
catchbb = terminator.catch_dest
if bb_rename_succ[catchbb] == 0
push!(worklist, catchbb)
if catchbb 0
if bb_rename_succ[catchbb] == 0
push!(worklist, catchbb)
end
end
elseif isa(terminator, GotoNode) || isa(terminator, ReturnNode)
# No implicit fall through. Schedule from work list.
Expand Down
29 changes: 28 additions & 1 deletion Compiler/test/irpasses.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1816,7 +1816,34 @@ function f53521()
end
end
end
@test code_typed(f53521)[1][2] === Nothing
let (ir,rt) = only(Base.code_ircode(f53521, ()))
@test rt == Nothing
Compiler.verify_ir(ir)
Compiler.cfg_simplify!(ir)
Compiler.verify_ir(ir)
end

Base.@assume_effects :foldable Base.@constprop :aggressive function f53521(x::Int, ::Int)
VALUE = ScopedValue(x)
@with VALUE => 2 begin
for i = 1
@with VALUE => 3 begin
local v
try
v = sin(VALUE[])
catch
v = nothing
end
return v
end
end
end
end
let (ir,rt) = only(Base.code_ircode((Int,)) do y
f53521(1, y)
end)
@test rt == Union{Nothing,Float64}
end

# Test that adce_pass! sets Refined on PhiNode values
let code = Any[
Expand Down

0 comments on commit f6ebc4b

Please sign in to comment.