* [backport] fix #11320 * fix test for 32 bit test
This commit is contained in:
parent
0a1cb631a2
commit
20d0ef8afb
4 changed files with 17 additions and 6 deletions
|
|
@ -291,7 +291,7 @@ proc computeSizeAlign(conf: ConfigRef; typ: PType) =
|
||||||
of tyUncheckedArray:
|
of tyUncheckedArray:
|
||||||
let base = typ.lastSon
|
let base = typ.lastSon
|
||||||
computeSizeAlign(conf, base)
|
computeSizeAlign(conf, base)
|
||||||
typ.size = szUnknownSize
|
typ.size = 0
|
||||||
typ.align = base.align
|
typ.align = base.align
|
||||||
of tyEnum:
|
of tyEnum:
|
||||||
if firstOrd(conf, typ) < 0:
|
if firstOrd(conf, typ) < 0:
|
||||||
|
|
|
||||||
|
|
@ -877,8 +877,8 @@ when defined(nimHasalignOf):
|
||||||
proc offsetOfDotExpr(typeAccess: typed): int {.magic: "OffsetOf", noSideEffect, compileTime.}
|
proc offsetOfDotExpr(typeAccess: typed): int {.magic: "OffsetOf", noSideEffect, compileTime.}
|
||||||
|
|
||||||
template offsetOf*[T](t: typedesc[T]; member: untyped): int =
|
template offsetOf*[T](t: typedesc[T]; member: untyped): int =
|
||||||
var tmp: T
|
var tmp {.noinit.}: ptr T
|
||||||
offsetOfDotExpr(tmp.member)
|
offsetOfDotExpr(tmp[].member)
|
||||||
|
|
||||||
template offsetOf*[T](value: T; member: untyped): int =
|
template offsetOf*[T](value: T; member: untyped): int =
|
||||||
offsetOfDotExpr(value.member)
|
offsetOfDotExpr(value.member)
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,4 @@ invalid type: 'UncheckedArray[uint8]' for var
|
||||||
'''
|
'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
var
|
var byteUA: UncheckedArray[uint8]
|
||||||
rawMem = alloc0(20)
|
|
||||||
byteUA = cast[UncheckedArray[uint8]](rawMem)
|
|
||||||
|
|
|
||||||
|
|
@ -536,3 +536,16 @@ proc main() =
|
||||||
typeProcessing(mylocal)
|
typeProcessing(mylocal)
|
||||||
|
|
||||||
main()
|
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()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue