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

fixes #13314 #13372

Merged
merged 1 commit into from
Feb 8, 2020
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
13 changes: 9 additions & 4 deletions compiler/dfa.nim
Original file line number Diff line number Diff line change
Expand Up @@ -609,15 +609,16 @@ proc aliases*(obj, field: PNode): bool =

proc useInstrTargets*(ins: Instr; loc: PNode): bool =
assert ins.kind == use
sameTrees(ins.n, loc) or
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.
result = sameTrees(ins.n, loc) or
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.
# use x.f; question: does it affect the full 'x'? No.
# use x; question does it affect 'x.f'? Yes.

proc defInstrTargets*(ins: Instr; loc: PNode): bool =
assert ins.kind == def
sameTrees(ins.n, loc) or
ins.n.aliases(loc) # We can come here if loc is 'x.f' and ins.n is 'x' or the other way round.
result = sameTrees(ins.n, loc) or ins.n.aliases(loc)
Copy link
Contributor

@Clyybber Clyybber Feb 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird, when I tried to fix this, this didn't work..
EDIT: Nevermimd, missed the gen call.
Now use/defInstrTargets can be one and the same \o/

# We can come here if loc is 'x.f' and ins.n is 'x' or the other way round.
# def x.f; question: does it affect the full 'x'? No.
# def x; question: does it affect the 'x.f'? Yes.

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

proc genCall(c: var Con; n: PNode) =
gen(c, n[0])
Expand Down
26 changes: 25 additions & 1 deletion tests/arc/tmovebug.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
discard """
cmd: "nim c --gc:arc $file"
output: '''5'''
output: '''5
(w: 5)
(w: -5)
'''
"""

# move bug
Expand Down Expand Up @@ -62,3 +65,24 @@ proc main =

main()
echo destroyCounter

# bug #13314

type
O = object
v: int
R = ref object
w: int

proc `$`(r: R): string = $r[]

proc tbug13314 =
var t5 = R(w: 5)
var execute = proc () =
echo t5

execute()
t5.w = -5
execute()

tbug13314()