diff options
Diffstat (limited to 'tests/misc/tsizeof.nim')
-rw-r--r-- | tests/misc/tsizeof.nim | 58 |
1 files changed, 56 insertions, 2 deletions
diff --git a/tests/misc/tsizeof.nim b/tests/misc/tsizeof.nim index 7b92d3639..ce5334664 100644 --- a/tests/misc/tsizeof.nim +++ b/tests/misc/tsizeof.nim @@ -78,7 +78,7 @@ macro c_offsetof(fieldAccess: typed): int32 = ## Bullet proof implementation that works on actual offsetof operator ## in the c backend. Assuming of course this implementation is ## correct. - let s = if fieldAccess.kind == nnkCheckedFieldExpr: fieldAccess[0] + let s = if fieldAccess.kind == nnkCheckedFieldExpr: fieldAccess[0] else: fieldAccess let a = s[0].getTypeInst let b = s[1] @@ -346,6 +346,31 @@ testinstance: c: char d: int32 # unaligned + Kind = enum + K1, K2 + + AnotherEnum = enum + X1, X2, X3 + + MyObject = object + s: string + case k: Kind + of K1: nil + of K2: + x: float + y: int32 + z: AnotherEnum + + Stack[N: static int, T: object] = object + pad: array[128 - sizeof(array[N, ptr T]) - sizeof(int) - sizeof(pointer), byte] + stack: array[N, ptr T] + len*: int + rawMem: ptr array[N, T] + + Stack2[T: object] = object + pad: array[128 - sizeof(array[sizeof(T), ptr T]), byte] + + const trivialSize = sizeof(TrivialType) # needs to be able to evaluate at compile time proc main(): void = @@ -361,6 +386,9 @@ testinstance: var go : GenericObject[int64] var po : PaddingOfSetEnum33 var capo: MyCustomAlignPackedObject + var issue15516: MyObject + var issue12636_1: Stack[5, MyObject] + var issue12636_2: Stack2[MyObject] var e1: Enum1 @@ -379,7 +407,7 @@ testinstance: else: doAssert sizeof(SimpleAlignment) > 10 - testSizeAlignOf(t,a,b,c,d,e,f,g,ro,go,po, e1, e2, e4, e8, eoa, eob, capo) + testSizeAlignOf(t,a,b,c,d,e,f,g,ro,go,po, e1, e2, e4, e8, eoa, eob, capo, issue15516, issue12636_1, issue12636_2) type WithBitsize {.objectconfig.} = object @@ -686,3 +714,29 @@ reject: reject: const off8 = offsetof(MyPackedCaseObject, val5) + + +type + O0 = object + T0 = tuple[] + +doAssert sizeof(O0) == 1 +doAssert sizeof(T0) == 1 + + +type + # this thing may not have padding bytes at the end + PackedUnion* {.union, packed.} = object + a*: array[11, byte] + b*: int64 + +doAssert sizeof(PackedUnion) == 11 +doAssert alignof(PackedUnion) == 1 + +# bug #22553 +type + ChunkObj = object + data: UncheckedArray[byte] + +doAssert sizeof(ChunkObj) == 1 +doAssert offsetOf(ChunkObj, data) == 1 |