Fix for sizeof bitsize combination (#10227)

* fix #10082

* added test
This commit is contained in:
Arne Döring
2019-01-07 18:09:57 +01:00
committed by GitHub
parent 387831d657
commit abad758a7e
2 changed files with 20 additions and 3 deletions

View File

@@ -154,12 +154,17 @@ proc computePackedObjectOffsetsFoldFunction(conf: ConfigRef; n: PNode, initialOf
if result == szIllegalRecursion:
break
of nkSym:
var size = szUnknownSize
if n.sym.bitsize == 0:
computeSizeAlign(conf, n.sym.typ)
n.sym.offset = initialOffset.int
result = n.sym.offset + n.sym.typ.size
else:
size = n.sym.typ.size.int
if initialOffset == szUnknownSize or size == szUnknownSize:
n.sym.offset = szUnknownSize
result = szUnknownSize
else:
n.sym.offset = int(initialOffset)
result = initialOffset + n.sym.typ.size
else:
result = szUnknownSize

View File

@@ -402,6 +402,18 @@ type
assert sizeof(C) == 3
type
MixedBitsize = object {.packed.}
a: uint32
b {.bitsize: 8.}: uint8
c {.bitsize: 1.}: uint8
d {.bitsize: 7.}: uint8
e {.bitsize: 16.}: uint16
f: uint32
doAssert sizeof(MixedBitsize) == 12
if failed:
quit("FAIL")
else: