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
commit 7c2ac98880
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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(@[])