diff options
author | Arne Döring <arne.doering@gmx.net> | 2019-07-03 08:00:40 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-07-03 08:00:40 +0200 |
commit | 20d0ef8afbd4b7b74c24f069841cce52cd5beaff (patch) | |
tree | f0b0a4e12fa34446d92cab94adf4ea1b8fc1b83a | |
parent | 0a1cb631a2c36574180469013425873984d82b16 (diff) | |
download | Nim-20d0ef8afbd4b7b74c24f069841cce52cd5beaff.tar.gz |
[backport] fix #11320 (#11538)
* [backport] fix #11320 * fix test for 32 bit test
-rw-r--r-- | compiler/sizealignoffsetimpl.nim | 2 | ||||
-rw-r--r-- | lib/system.nim | 4 | ||||
-rw-r--r-- | tests/errmsgs/tuncheckedarrayvar.nim | 4 | ||||
-rw-r--r-- | tests/misc/tsizeof.nim | 13 |
4 files changed, 17 insertions, 6 deletions
diff --git a/compiler/sizealignoffsetimpl.nim b/compiler/sizealignoffsetimpl.nim index 66fb3dc5b..cf8f296b4 100644 --- a/compiler/sizealignoffsetimpl.nim +++ b/compiler/sizealignoffsetimpl.nim @@ -291,7 +291,7 @@ proc computeSizeAlign(conf: ConfigRef; typ: PType) = of tyUncheckedArray: let base = typ.lastSon computeSizeAlign(conf, base) - typ.size = szUnknownSize + typ.size = 0 typ.align = base.align of tyEnum: if firstOrd(conf, typ) < 0: diff --git a/lib/system.nim b/lib/system.nim index 256410522..d0149a118 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -877,8 +877,8 @@ when defined(nimHasalignOf): proc offsetOfDotExpr(typeAccess: typed): int {.magic: "OffsetOf", noSideEffect, compileTime.} template offsetOf*[T](t: typedesc[T]; member: untyped): int = - var tmp: T - offsetOfDotExpr(tmp.member) + var tmp {.noinit.}: ptr T + offsetOfDotExpr(tmp[].member) template offsetOf*[T](value: T; member: untyped): int = offsetOfDotExpr(value.member) diff --git a/tests/errmsgs/tuncheckedarrayvar.nim b/tests/errmsgs/tuncheckedarrayvar.nim index 17965914a..9376a0150 100644 --- a/tests/errmsgs/tuncheckedarrayvar.nim +++ b/tests/errmsgs/tuncheckedarrayvar.nim @@ -4,6 +4,4 @@ invalid type: 'UncheckedArray[uint8]' for var ''' """ -var - rawMem = alloc0(20) - byteUA = cast[UncheckedArray[uint8]](rawMem) +var byteUA: UncheckedArray[uint8] diff --git a/tests/misc/tsizeof.nim b/tests/misc/tsizeof.nim index 50d1c645a..f3d946a56 100644 --- a/tests/misc/tsizeof.nim +++ b/tests/misc/tsizeof.nim @@ -536,3 +536,16 @@ proc main() = typeProcessing(mylocal) main() + +# issue #11320 use UncheckedArray + +type + Payload = object + something: int8 + vals: UncheckedArray[int32] + +proc payloadCheck() = + doAssert offsetOf(Payload, vals) == 4 + doAssert sizeOf(Payload) == 4 + +payloadCheck() |