Skip to content

Commit 240174d

Browse files
authored
fixes #13314 (#13372)
1 parent 038f47e commit 240174d

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

compiler/dfa.nim

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -609,15 +609,16 @@ proc aliases*(obj, field: PNode): bool =
609609

610610
proc useInstrTargets*(ins: Instr; loc: PNode): bool =
611611
assert ins.kind == use
612-
sameTrees(ins.n, loc) or
613-
ins.n.aliases(loc) or loc.aliases(ins.n) # We can come here if loc is 'x.f' and ins.n is 'x' or the other way round.
612+
result = sameTrees(ins.n, loc) or
613+
ins.n.aliases(loc) or loc.aliases(ins.n)
614+
# We can come here if loc is 'x.f' and ins.n is 'x' or the other way round.
614615
# use x.f; question: does it affect the full 'x'? No.
615616
# use x; question does it affect 'x.f'? Yes.
616617

617618
proc defInstrTargets*(ins: Instr; loc: PNode): bool =
618619
assert ins.kind == def
619-
sameTrees(ins.n, loc) or
620-
ins.n.aliases(loc) # We can come here if loc is 'x.f' and ins.n is 'x' or the other way round.
620+
result = sameTrees(ins.n, loc) or ins.n.aliases(loc)
621+
# We can come here if loc is 'x.f' and ins.n is 'x' or the other way round.
621622
# def x.f; question: does it affect the full 'x'? No.
622623
# def x; question: does it affect the 'x.f'? Yes.
623624

@@ -678,6 +679,10 @@ proc genDef(c: var Con; n: PNode) =
678679
c.code.add Instr(n: n, kind: def)
679680
elif isAnalysableFieldAccess(n, c.owner):
680681
c.code.add Instr(n: n, kind: def)
682+
else:
683+
# bug #13314: An assignment to t5.w = -5 is a usage of 't5'
684+
# we still need to gather the use information:
685+
gen(c, n)
681686

682687
proc genCall(c: var Con; n: PNode) =
683688
gen(c, n[0])

tests/arc/tmovebug.nim

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
discard """
22
cmd: "nim c --gc:arc $file"
3-
output: '''5'''
3+
output: '''5
4+
(w: 5)
5+
(w: -5)
6+
'''
47
"""
58

69
# move bug
@@ -62,3 +65,24 @@ proc main =
6265

6366
main()
6467
echo destroyCounter
68+
69+
# bug #13314
70+
71+
type
72+
O = object
73+
v: int
74+
R = ref object
75+
w: int
76+
77+
proc `$`(r: R): string = $r[]
78+
79+
proc tbug13314 =
80+
var t5 = R(w: 5)
81+
var execute = proc () =
82+
echo t5
83+
84+
execute()
85+
t5.w = -5
86+
execute()
87+
88+
tbug13314()

0 commit comments

Comments
 (0)