]>
git.saurik.com Git - apple/xnu.git/blob - tests/intrusive_shared_ptr_src/abi.size_alignment.cpp
2 // This tests that the alignment and size of a class are the same whether
3 // they have a `T*` or a shared pointer data member.
6 #include <libkern/c++/intrusive_shared_ptr.h>
7 #include "test_policy.h"
9 #include <darwintest.h>
14 test_shared_ptr
<int> ptr
;
21 static_assert(sizeof(FooShared
) == sizeof(FooRaw
));
22 static_assert(alignof(FooShared
) == alignof(FooRaw
));
23 static_assert(offsetof(FooShared
, ptr
) == offsetof(FooRaw
, ptr
));
29 test_shared_ptr
<int> ptr
;
37 static_assert(sizeof(FooShared
) == sizeof(FooRaw
));
38 static_assert(alignof(FooShared
) == alignof(FooRaw
));
39 static_assert(offsetof(FooShared
, ptr
) == offsetof(FooRaw
, ptr
));
45 test_shared_ptr
<int> ptr
;
55 static_assert(sizeof(FooShared
) == sizeof(FooRaw
));
56 static_assert(alignof(FooShared
) == alignof(FooRaw
));
57 static_assert(offsetof(FooShared
, ptr
) == offsetof(FooRaw
, ptr
));
64 test_shared_ptr
<int> ptr
;
75 static_assert(sizeof(FooShared
) == sizeof(FooRaw
));
76 static_assert(alignof(FooShared
) == alignof(FooRaw
));
77 static_assert(offsetof(FooShared
, ptr
) == offsetof(FooRaw
, ptr
));
81 struct __attribute__((packed
)) FooShared
{
84 test_shared_ptr
<int> ptr
;
88 struct __attribute__((packed
)) FooRaw
{
95 static_assert(sizeof(FooShared
) == sizeof(FooRaw
));
96 static_assert(alignof(FooShared
) == alignof(FooRaw
));
97 static_assert(offsetof(FooShared
, ptr
) == offsetof(FooRaw
, ptr
));
104 test_shared_ptr
<int> ptr
;
105 int i
__attribute__((packed
));
112 int i
__attribute__((packed
));
115 static_assert(sizeof(FooShared
) == sizeof(FooRaw
));
116 static_assert(alignof(FooShared
) == alignof(FooRaw
));
117 static_assert(offsetof(FooShared
, ptr
) == offsetof(FooRaw
, ptr
));
124 test_shared_ptr
<int> ptr
__attribute__((packed
));
131 int* ptr
__attribute__((packed
));
135 static_assert(sizeof(FooShared
) == sizeof(FooRaw
));
136 static_assert(alignof(FooShared
) == alignof(FooRaw
));
137 static_assert(offsetof(FooShared
, ptr
) == offsetof(FooRaw
, ptr
));
140 T_DECL(abi_size_alignment
, "intrusive_shared_ptr.abi.size_alignment") {
141 T_PASS("intrusive_shared_ptr.abi.size_alignment compile-time tests passed");