Skip to content

Commit

Permalink
Have copy(ci::CodeInfo) also copy ci.edges. (#33523)
Browse files Browse the repository at this point in the history
Before this commit, it was a shallow-copy, so the array was shared
between the orginal ci and the copy.
  • Loading branch information
NHDaly authored and JeffBezanson committed Oct 11, 2019
1 parent e0f9045 commit 2b1fc4c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 3 additions & 2 deletions base/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ function copy(c::CodeInfo)
cnew.slotflags = copy(cnew.slotflags)
cnew.codelocs = copy(cnew.codelocs)
cnew.linetable = copy(cnew.linetable)
cnew.ssaflags = copy(cnew.ssaflags)
ssavaluetypes = cnew.ssavaluetypes
cnew.ssaflags = copy(cnew.ssaflags)
cnew.edges = cnew.edges === nothing ? nothing : copy(cnew.edges)
ssavaluetypes = cnew.ssavaluetypes
ssavaluetypes isa Vector{Any} && (cnew.ssavaluetypes = copy(ssavaluetypes))
return cnew
end
Expand Down
10 changes: 10 additions & 0 deletions test/copy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,13 @@ end
let x = Bar17149()
@test deepcopy(x) !== x
end

@testset "copying CodeInfo" begin
_testfunc() = nothing
ci,_ = code_typed(_testfunc, ())[1]
ci.edges = [_testfunc]

ci2 = copy(ci)
# Test that edges are not shared
@test ci2.edges !== ci.edges
end

0 comments on commit 2b1fc4c

Please sign in to comment.