Skip to content

Commit 5ab8b8c

Browse files
committed
fix #15704 wrong VM register was freed
1 parent e18fc69 commit 5ab8b8c

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

compiler/vmgen.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1515,7 +1515,7 @@ proc genAsgn(c: PCtx; le, ri: PNode; requiresCopy: bool) =
15151515
let idx = genField(c, le[1])
15161516
let tmp = c.genx(ri)
15171517
c.preventFalseAlias(le, opcWrObj, dest, idx, tmp)
1518-
c.freeTemp(idx)
1518+
# c.freeTemp(idx) # BUGFIX: idx is an immediate (field position), not a register
15191519
c.freeTemp(tmp)
15201520
c.freeTemp(dest)
15211521
of nkDerefExpr, nkHiddenDeref:

tests/vm/tvmmisc.nim

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,3 +281,45 @@ block: # bug #8007
281281
# OK with seq & object variants
282282
const d = @[Cost(kind: Fixed, cost: 999), Cost(kind: Dynamic, handler: foo)]
283283
doAssert $d == "@[(kind: Fixed, cost: 999), (kind: Dynamic, handler: ...)]"
284+
285+
286+
block: # bug #15704
287+
proc bar2(head: string): string = "asdf"
288+
proc gook(u1: int) = discard
289+
290+
type PathEntry = object
291+
kind: int
292+
path: string
293+
294+
iterator globOpt(): int =
295+
var u1: int
296+
297+
gook(u1)
298+
gook(u1)
299+
gook(u1)
300+
gook(u1)
301+
gook(u1)
302+
gook(u1)
303+
gook(u1)
304+
gook(u1)
305+
gook(u1)
306+
gook(u1)
307+
gook(u1)
308+
gook(u1)
309+
gook(u1)
310+
gook(u1)
311+
312+
var entry = PathEntry()
313+
entry.path = bar2("")
314+
echo "here2"
315+
316+
proc processAux(a: float) = discard
317+
318+
template bar(iter: untyped): untyped =
319+
var ret: float
320+
for x in iter: break
321+
ret
322+
323+
proc main() =
324+
processAux(bar(globOpt()))
325+
static: main()

0 commit comments

Comments
 (0)