diff options
author | ringabout <43030857+ringabout@users.noreply.github.com> | 2022-11-26 14:48:11 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-26 07:48:11 +0100 |
commit | b57a9637e8aab931b741c9dfe4602a0168a2e655 (patch) | |
tree | 4b6cf6e5fe852ebf2a485c84adabd46d95e69222 | |
parent | 2709898a5eeb97ca4692296b25932aeb15456c0d (diff) | |
download | Nim-b57a9637e8aab931b741c9dfe4602a0168a2e655.tar.gz |
fixes #20914; fixes the alignment of big sets (#20918)
* fixes #20914; fixes the align of bug sets * add a test for alignof
-rw-r--r-- | compiler/sizealignoffsetimpl.nim | 4 | ||||
-rw-r--r-- | tests/misc/tsizeof3.nim | 29 |
2 files changed, 31 insertions, 2 deletions
diff --git a/compiler/sizealignoffsetimpl.nim b/compiler/sizealignoffsetimpl.nim index 009acf6eb..987bcde99 100644 --- a/compiler/sizealignoffsetimpl.nim +++ b/compiler/sizealignoffsetimpl.nim @@ -319,10 +319,10 @@ proc computeSizeAlign(conf: ConfigRef; typ: PType) = typ.align = int16(conf.floatInt64Align) elif align(length, 8) mod 8 == 0: typ.size = align(length, 8) div 8 - typ.align = int16(conf.floatInt64Align) + typ.align = 1 else: typ.size = align(length, 8) div 8 + 1 - typ.align = int16(conf.floatInt64Align) + typ.align = 1 of tyRange: computeSizeAlign(conf, typ[0]) typ.size = typ[0].size diff --git a/tests/misc/tsizeof3.nim b/tests/misc/tsizeof3.nim index 1215b4bcd..f0ba8c4d0 100644 --- a/tests/misc/tsizeof3.nim +++ b/tests/misc/tsizeof3.nim @@ -27,3 +27,32 @@ type static: doAssert(compiles(offsetOf(Payload, vals))) + + +type + GoodboySave* {.bycopy.} = object + saveCount: uint8 + savePoint: uint16 + shards: uint32 + friendCount: uint8 + friendCards: set[0..255] + locationsKnown: set[0..127] + locationsUnlocked: set[0..127] + pickupsObtained: set[0..127] + pickupsUsed: set[0..127] + pickupCount: uint8 + +block: # bug #20914 + block: + proc csizeof[T](a: T): int {.importc:"sizeof", nodecl.} + + var s: GoodboySave + doAssert sizeof(s) == 108 + doAssert csizeof(s) == static(sizeof(s)) + + block: + proc calignof[T](a: T): int {.importc:"alignof", header: "<stdalign.h>".} + + var s: set[0..256] + doAssert alignof(s) == 1 + doAssert calignof(s) == static(alignof(s)) |