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 #19404 #19515

Merged
merged 2 commits into from
Feb 12, 2022
Merged
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
21 changes: 13 additions & 8 deletions compiler/vm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ proc bailOut(c: PCtx; tos: PStackFrame) =
when not defined(nimComputedGoto):
{.pragma: computedGoto.}

proc ensureKind(n: var TFullReg, kind: TRegisterKind) =
if n.kind != kind:
n = TFullReg(kind: kind)
proc ensureKind(n: var TFullReg, k: TRegisterKind) {.inline.} =
if n.kind != k:
n = TFullReg(kind: k)

template ensureKind(k: untyped) {.dirty.} =
ensureKind(regs[ra], k)
Expand Down Expand Up @@ -521,6 +521,11 @@ template maybeHandlePtr(node2: PNode, reg: TFullReg, isAssign2: bool): bool =
when not defined(nimHasSinkInference):
{.pragma: nosinks.}

template takeAddress(reg, source) =
reg.nodeAddr = addr source
when defined(gcDestructors):
GC_ref source

proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
var pc = start
var tos = tos
Expand Down Expand Up @@ -679,7 +684,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
let idx = regs[rc].intVal.int
let src = if regs[rb].kind == rkNode: regs[rb].node else: regs[rb].nodeAddr[]
if src.kind notin {nkEmpty..nkTripleStrLit} and idx <% src.len:
regs[ra].nodeAddr = addr src.sons[idx]
takeAddress regs[ra], src.sons[idx]
else:
stackTrace(c, tos, pc, formatErrorIndexBound(idx, src.safeLen-1))
of opcLdStrIdx:
Expand Down Expand Up @@ -747,11 +752,11 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
of nkObjConstr:
let n = src.sons[rc + 1]
if n.kind == nkExprColonExpr:
regs[ra].nodeAddr = addr n.sons[1]
takeAddress regs[ra], n.sons[1]
else:
regs[ra].nodeAddr = addr src.sons[rc + 1]
takeAddress regs[ra], src.sons[rc + 1]
else:
regs[ra].nodeAddr = addr src.sons[rc]
takeAddress regs[ra], src.sons[rc]
of opcWrObj:
# a.b = c
decodeBC(rkNode)
Expand All @@ -778,7 +783,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
decodeB(rkNodeAddr)
case regs[rb].kind
of rkNode:
regs[ra].nodeAddr = addr(regs[rb].node)
takeAddress regs[ra], regs[rb].node
of rkNodeAddr: # bug #14339
regs[ra].nodeAddr = regs[rb].nodeAddr
else:
Expand Down