From 7c2ac988805111df999dd4f586471627ee80efbb Mon Sep 17 00:00:00 2001 From: Saem Ghani Date: Tue, 23 Feb 2021 00:02:06 -0800 Subject: [PATCH] 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. --- compiler/vm.nim | 2 +- tests/vm/t17039.nim | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 tests/vm/t17039.nim diff --git a/compiler/vm.nim b/compiler/vm.nim index 246d9d4d23..ba14f2d51b 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -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: diff --git a/tests/vm/t17039.nim b/tests/vm/t17039.nim new file mode 100644 index 0000000000..f92c93f30a --- /dev/null +++ b/tests/vm/t17039.nim @@ -0,0 +1,10 @@ +type + Obj1 = object + case kind: bool + of false: + field: seq[int] + else: discard + +static: + var obj1 = Obj1() + obj1.field.add(@[])