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

Attempting to access Vector{Core.Compiler.DomTreeNode} at index [0] when optimizing a function #54596

Closed
KristofferC opened this issue May 28, 2024 · 2 comments · Fixed by #54765
Labels
compiler:optimizer Optimization passes (mostly in base/compiler/ssair/)
Milestone

Comments

@KristofferC
Copy link
Member

Repro:

julia> using GMT

julia> code_warntype(show, Tuple{Base.GenericIOBuffer{GenericMemory{:not_atomic, UInt8, Core.AddrSpace{Core}(0x00)}}, GMT.Gdal.IDataset}; optimize=true)
ERROR: BoundsError: attempt to access 124-element Vector{Core.Compiler.DomTreeNode} at index [0]
Stacktrace:
  [1] throw_boundserror(A::Vector{Core.Compiler.DomTreeNode}, I::Tuple{Int64})
    @ Core.Compiler ./essentials.jl:14
  [2] getindex
    @ ./essentials.jl:894 [inlined]
  [3] _dominates(domtree::Core.Compiler.GenericDomTree{false}, bb1::Int64, bb2::Int64)
    @ Core.Compiler ./compiler/ssair/domtree.jl:622
  [4] dominates
    @ ./compiler/ssair/domtree.jl:605 [inlined]
  [5] try_resolve_finalizer!(ir::Core.Compiler.IRCode, idx::Int64, finalizer_idx::Int64, defuse::Core.Compiler.SSADefUse, inlining::Core.Compiler.InliningState{…}, lazydomtree::Core.Compiler.LazyGenericDomtree{…}, lazypostdomtree::Core.Compiler.LazyGenericDomtree{…}, info::Core.Compiler.CallInfo)
    @ Core.Compiler ./compiler/ssair/passes.jl:1619
  [6] sroa_mutables!(ir::Core.Compiler.IRCode, defuses::Core.Compiler.IdDict{…}, used_ssas::Vector{…}, lazydomtree::Core.Compiler.LazyGenericDomtree{…}, inlining::Core.Compiler.InliningState{…})

Seems to be caused by #53739 because reverting that PR seems to fix it on the 1.11 backport branch.

@KristofferC KristofferC added the compiler:optimizer Optimization passes (mostly in base/compiler/ssair/) label May 28, 2024
@KristofferC KristofferC added this to the 1.11 milestone May 28, 2024
@maleadt
Copy link
Member

maleadt commented May 29, 2024

MWE:

mutable struct IFeatureLayer
    ptr::Ptr{Cvoid}
    function IFeatureLayer()
        layer = new()
        finalizer(destroy, layer)
    end
end
destroy(layer) = layer.ptr = 0
getgeomtype(layer) = ccall(0, UInt32, (Ptr{Cvoid},), layer.ptr)

function main()
    layer = IFeatureLayer()
    get(identity, getgeomtype(layer), getgeomtype(layer))
    layer.ptr
end
Base.code_ircode(main, Tuple{})

@maleadt
Copy link
Member

maleadt commented May 30, 2024

Seems to be caused by #53739 because reverting that PR seems to fix it on the 1.11 backport branch.

Confirmed that by bisecting the above MWE on the master branch. (cc @topolarity)

KristofferC pushed a commit that referenced this issue Jun 13, 2024
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:optimizer Optimization passes (mostly in base/compiler/ssair/)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants