Skip to content

Commit

Permalink
Handle no-postdominator case in finalizer pass (#54765)
Browse files Browse the repository at this point in the history
This pass was assuming that the post-dominator of all finalizer uses
exists as a real BB in the CFG.

Resolves #54596

(cherry picked from commit 6ec2b1f)
  • Loading branch information
topolarity authored and KristofferC committed Jun 13, 2024
1 parent 63b66b8 commit 95a3792
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions base/compiler/ssair/domtree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,8 @@ end
Compute the nearest common (post-)dominator of `a` and `b`.
"""
function nearest_common_dominator(domtree::GenericDomTree, a::BBNumber, b::BBNumber)
a == 0 && return a
b == 0 && return b
alevel = domtree.nodes[a].level
blevel = domtree.nodes[b].level
# W.l.g. assume blevel <= alevel
Expand Down
1 change: 1 addition & 0 deletions base/compiler/ssair/passes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,7 @@ function try_resolve_finalizer!(ir::IRCode, idx::Int, finalizer_idx::Int, defuse
end
all(check_defuse, defuse.uses) || return nothing
all(check_defuse, defuse.defs) || return nothing
bb_insert_block != 0 || return nothing # verify post-dominator of all uses exists

# Check #3
dominates(domtree, finalizer_bb, bb_insert_block) || return nothing
Expand Down
21 changes: 21 additions & 0 deletions test/compiler/irpasses.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1820,3 +1820,24 @@ function f53521()
end
end
@test code_typed(f53521)[1][2] === Nothing

# https://github.com/JuliaLang/julia/issues/54596
# finalized object's uses have no postdominator
let f = (x)->nothing, mi = Base.method_instance(f, (Base.RefValue{Nothing},)), code = Any[
# Basic Block 1
Expr(:new, Base.RefValue{Nothing}, nothing)
Expr(:call, Core.finalizer, f, SSAValue(1), true, mi)
GotoIfNot(false, 6)
# Basic Block 2
Expr(:call, Base.getfield, SSAValue(1), :x)
ReturnNode(SSAValue(4))
# Basic Block 3
Expr(:call, Base.getfield, SSAValue(1), :x)
ReturnNode(SSAValue(6))
]
ir = make_ircode(code; ssavaluetypes=Any[Base.RefValue{Nothing}, Nothing, Any, Nothing, Any, Nothing, Any])
inlining = Core.Compiler.InliningState(Core.Compiler.NativeInterpreter())
Core.Compiler.verify_ir(ir)
ir = Core.Compiler.sroa_pass!(ir, inlining)
Core.Compiler.verify_ir(ir)
end

0 comments on commit 95a3792

Please sign in to comment.