Skip to content

Commit 2b1fc4c

Browse files
NHDalyJeffBezanson
authored andcommitted
Have copy(ci::CodeInfo) also copy ci.edges. (#33523)
Before this commit, it was a shallow-copy, so the array was shared between the orginal ci and the copy.
1 parent e0f9045 commit 2b1fc4c

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

base/expr.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ function copy(c::CodeInfo)
6767
cnew.slotflags = copy(cnew.slotflags)
6868
cnew.codelocs = copy(cnew.codelocs)
6969
cnew.linetable = copy(cnew.linetable)
70-
cnew.ssaflags = copy(cnew.ssaflags)
71-
ssavaluetypes = cnew.ssavaluetypes
70+
cnew.ssaflags = copy(cnew.ssaflags)
71+
cnew.edges = cnew.edges === nothing ? nothing : copy(cnew.edges)
72+
ssavaluetypes = cnew.ssavaluetypes
7273
ssavaluetypes isa Vector{Any} && (cnew.ssavaluetypes = copy(ssavaluetypes))
7374
return cnew
7475
end

test/copy.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,13 @@ end
193193
let x = Bar17149()
194194
@test deepcopy(x) !== x
195195
end
196+
197+
@testset "copying CodeInfo" begin
198+
_testfunc() = nothing
199+
ci,_ = code_typed(_testfunc, ())[1]
200+
ci.edges = [_testfunc]
201+
202+
ci2 = copy(ci)
203+
# Test that edges are not shared
204+
@test ci2.edges !== ci.edges
205+
end

0 commit comments

Comments
 (0)