Fixes #17039 - ldObj checks node/nodeAddr access (#17123)

Checked field expressions, such as an object variant field access results in
occasionally broken address analysis crashing the VM. This guard added here
mimics guarded access in ldObjAddr as well. This is to prevent a crash, while a
fix is devised.
This commit is contained in:
Saem Ghani
2021-02-23 00:02:06 -08:00
committed by GitHub
parent 4e619a6bea
commit 7c2ac98880
2 changed files with 11 additions and 1 deletions

View File

@@ -711,7 +711,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
of opcLdObj:
# a = b.c
decodeBC(rkNode)
let src = regs[rb].node
let src = if regs[rb].kind == rkNode: regs[rb].node else: regs[rb].nodeAddr[]
case src.kind
of nkEmpty..nkNilLit:
# for nkPtrLit, this could be supported in the future, use something like:

10
tests/vm/t17039.nim Normal file
View File

@@ -0,0 +1,10 @@
type
Obj1 = object
case kind: bool
of false:
field: seq[int]
else: discard
static:
var obj1 = Obj1()
obj1.field.add(@[])