From 0ecaaa85e9395dc7ae947d6466698cef66f48f5c Mon Sep 17 00:00:00 2001 From: Araq Date: Sun, 5 May 2019 16:08:16 +0200 Subject: [PATCH] fixes #9403 --- compiler/ccgexprs.nim | 2 +- tests/ccgbugs/tunsafeaddr.nim | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index e03c4b1c14..244b96108a 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -1912,7 +1912,7 @@ proc genOrd(p: BProc, e: PNode, d: var TLoc) = proc genSomeCast(p: BProc, e: PNode, d: var TLoc) = const - ValueTypes = {tyTuple, tyObject, tyArray, tyOpenArray, tyVarargs} + ValueTypes = {tyTuple, tyObject, tyArray, tyOpenArray, tyVarargs, tyUncheckedArray} # we use whatever C gives us. Except if we have a value-type, we need to go # through its address: var a: TLoc diff --git a/tests/ccgbugs/tunsafeaddr.nim b/tests/ccgbugs/tunsafeaddr.nim index 8d0a9d8cb5..f868739ded 100644 --- a/tests/ccgbugs/tunsafeaddr.nim +++ b/tests/ccgbugs/tunsafeaddr.nim @@ -1,5 +1,6 @@ discard """ - output: '''12''' + output: '''12 +4''' """ {.emit: """ @@ -26,3 +27,21 @@ p(@[1]) q(@[1]) main() + +# bug #9403 + +type + MyObj = ref object + len: int + val: UncheckedArray[uint64] + +proc spot(x: MyObj): int64 = + result = cast[UncheckedArray[int64]](x.val)[0] + +proc newMyObj(len: int): MyObj = + unsafeNew(result, sizeof(result[]) + len * sizeof(uint64)) + result.len = len + result.val[0] = 4u64 + result.val[1] = 8u64 + +echo spot(newMyObj(2))