Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle no-postdominator case in finalizer pass #54765

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1614,6 +1614,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 @@ -1949,3 +1949,24 @@ let code = Any[
# fallthrough
@test isdefined(ir[SSAValue(gotoifnot+1)][:inst]::ReturnNode, :val)
end

# 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