diff options
author | Arne Döring <arne.doering@gmx.net> | 2019-01-07 18:09:57 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-07 18:09:57 +0100 |
commit | abad758a7eff72e9f97224c400e1b48d09ecd97a (patch) | |
tree | 03707e3429fc9e21c656a37b0e95138770a04607 | |
parent | 387831d657bcbd130b7e739e4d58f7ccc29adae9 (diff) | |
download | Nim-abad758a7eff72e9f97224c400e1b48d09ecd97a.tar.gz |
Fix for sizeof bitsize combination (#10227)
* fix #10082 * added test
-rw-r--r-- | compiler/sizealignoffsetimpl.nim | 11 | ||||
-rw-r--r-- | tests/misc/tsizeof.nim | 12 |
2 files changed, 20 insertions, 3 deletions
diff --git a/compiler/sizealignoffsetimpl.nim b/compiler/sizealignoffsetimpl.nim index ea4730f57..fb256b895 100644 --- a/compiler/sizealignoffsetimpl.nim +++ b/compiler/sizealignoffsetimpl.nim @@ -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 diff --git a/tests/misc/tsizeof.nim b/tests/misc/tsizeof.nim index 4422e900e..25c566171 100644 --- a/tests/misc/tsizeof.nim +++ b/tests/misc/tsizeof.nim @@ -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: |