1bb611c8fSApple OSS Distributions // 2bb611c8fSApple OSS Distributions // This tests that the alignment and size of a class are the same whether 3bb611c8fSApple OSS Distributions // they have a `T*` or a shared pointer data member. 4bb611c8fSApple OSS Distributions // 5bb611c8fSApple OSS Distributions 6bb611c8fSApple OSS Distributions #include <libkern/c++/intrusive_shared_ptr.h> 7bb611c8fSApple OSS Distributions #include "test_policy.h" 8bb611c8fSApple OSS Distributions #include <cstddef> 9bb611c8fSApple OSS Distributions #include <darwintest.h> 10bb611c8fSApple OSS Distributions 11bb611c8fSApple OSS Distributions 12bb611c8fSApple OSS Distributions namespace ns1 { 13bb611c8fSApple OSS Distributions struct FooShared { 14bb611c8fSApple OSS Distributions test_shared_ptr<int> ptr; 15bb611c8fSApple OSS Distributions }; 16bb611c8fSApple OSS Distributions 17bb611c8fSApple OSS Distributions struct FooRaw { 18bb611c8fSApple OSS Distributions int* ptr; 19bb611c8fSApple OSS Distributions }; 20bb611c8fSApple OSS Distributions 21bb611c8fSApple OSS Distributions static_assert(sizeof(FooShared) == sizeof(FooRaw)); 22bb611c8fSApple OSS Distributions static_assert(alignof(FooShared) == alignof(FooRaw)); 23bb611c8fSApple OSS Distributions static_assert(offsetof(FooShared, ptr) == offsetof(FooRaw, ptr)); 24bb611c8fSApple OSS Distributions } 25bb611c8fSApple OSS Distributions 26bb611c8fSApple OSS Distributions namespace ns2 { 27bb611c8fSApple OSS Distributions struct FooShared { 28bb611c8fSApple OSS Distributions int i; 29bb611c8fSApple OSS Distributions test_shared_ptr<int> ptr; 30bb611c8fSApple OSS Distributions }; 31bb611c8fSApple OSS Distributions 32bb611c8fSApple OSS Distributions struct FooRaw { 33bb611c8fSApple OSS Distributions int i; 34bb611c8fSApple OSS Distributions int* ptr; 35bb611c8fSApple OSS Distributions }; 36bb611c8fSApple OSS Distributions 37bb611c8fSApple OSS Distributions static_assert(sizeof(FooShared) == sizeof(FooRaw)); 38bb611c8fSApple OSS Distributions static_assert(alignof(FooShared) == alignof(FooRaw)); 39bb611c8fSApple OSS Distributions static_assert(offsetof(FooShared, ptr) == offsetof(FooRaw, ptr)); 40bb611c8fSApple OSS Distributions } 41bb611c8fSApple OSS Distributions 42bb611c8fSApple OSS Distributions namespace ns3 { 43bb611c8fSApple OSS Distributions struct FooShared { 44bb611c8fSApple OSS Distributions char c; 45bb611c8fSApple OSS Distributions test_shared_ptr<int> ptr; 46bb611c8fSApple OSS Distributions int i; 47bb611c8fSApple OSS Distributions }; 48bb611c8fSApple OSS Distributions 49bb611c8fSApple OSS Distributions struct FooRaw { 50bb611c8fSApple OSS Distributions char c; 51bb611c8fSApple OSS Distributions int* ptr; 52bb611c8fSApple OSS Distributions int i; 53bb611c8fSApple OSS Distributions }; 54bb611c8fSApple OSS Distributions 55bb611c8fSApple OSS Distributions static_assert(sizeof(FooShared) == sizeof(FooRaw)); 56bb611c8fSApple OSS Distributions static_assert(alignof(FooShared) == alignof(FooRaw)); 57bb611c8fSApple OSS Distributions static_assert(offsetof(FooShared, ptr) == offsetof(FooRaw, ptr)); 58bb611c8fSApple OSS Distributions } 59bb611c8fSApple OSS Distributions 60bb611c8fSApple OSS Distributions namespace ns4 { 61bb611c8fSApple OSS Distributions struct FooShared { 62bb611c8fSApple OSS Distributions char c; 63bb611c8fSApple OSS Distributions unsigned int b : 5; 64bb611c8fSApple OSS Distributions test_shared_ptr<int> ptr; 65bb611c8fSApple OSS Distributions int i; 66bb611c8fSApple OSS Distributions }; 67bb611c8fSApple OSS Distributions 68bb611c8fSApple OSS Distributions struct FooRaw { 69bb611c8fSApple OSS Distributions char c; 70bb611c8fSApple OSS Distributions unsigned int b : 5; 71bb611c8fSApple OSS Distributions int* ptr; 72bb611c8fSApple OSS Distributions int i; 73bb611c8fSApple OSS Distributions }; 74bb611c8fSApple OSS Distributions 75bb611c8fSApple OSS Distributions static_assert(sizeof(FooShared) == sizeof(FooRaw)); 76bb611c8fSApple OSS Distributions static_assert(alignof(FooShared) == alignof(FooRaw)); 77bb611c8fSApple OSS Distributions static_assert(offsetof(FooShared, ptr) == offsetof(FooRaw, ptr)); 78bb611c8fSApple OSS Distributions } 79bb611c8fSApple OSS Distributions 80bb611c8fSApple OSS Distributions namespace ns5 { 81bb611c8fSApple OSS Distributions struct __attribute__((packed)) FooShared { 82bb611c8fSApple OSS Distributions char c; 83bb611c8fSApple OSS Distributions unsigned int b : 5; 84bb611c8fSApple OSS Distributions test_shared_ptr<int> ptr; 85bb611c8fSApple OSS Distributions int i; 86bb611c8fSApple OSS Distributions }; 87bb611c8fSApple OSS Distributions 88bb611c8fSApple OSS Distributions struct __attribute__((packed)) FooRaw { 89bb611c8fSApple OSS Distributions char c; 90bb611c8fSApple OSS Distributions unsigned int b : 5; 91bb611c8fSApple OSS Distributions int* ptr; 92bb611c8fSApple OSS Distributions int i; 93bb611c8fSApple OSS Distributions }; 94bb611c8fSApple OSS Distributions 95bb611c8fSApple OSS Distributions static_assert(sizeof(FooShared) == sizeof(FooRaw)); 96bb611c8fSApple OSS Distributions static_assert(alignof(FooShared) == alignof(FooRaw)); 97bb611c8fSApple OSS Distributions static_assert(offsetof(FooShared, ptr) == offsetof(FooRaw, ptr)); 98bb611c8fSApple OSS Distributions } 99bb611c8fSApple OSS Distributions 100bb611c8fSApple OSS Distributions namespace ns6 { 101bb611c8fSApple OSS Distributions struct FooShared { 102bb611c8fSApple OSS Distributions char c; 103bb611c8fSApple OSS Distributions unsigned int b : 5; 104bb611c8fSApple OSS Distributions test_shared_ptr<int> ptr; 105bb611c8fSApple OSS Distributions int i __attribute__((packed)); 106bb611c8fSApple OSS Distributions }; 107bb611c8fSApple OSS Distributions 108bb611c8fSApple OSS Distributions struct FooRaw { 109bb611c8fSApple OSS Distributions char c; 110bb611c8fSApple OSS Distributions unsigned int b : 5; 111bb611c8fSApple OSS Distributions int* ptr; 112bb611c8fSApple OSS Distributions int i __attribute__((packed)); 113bb611c8fSApple OSS Distributions }; 114bb611c8fSApple OSS Distributions 115bb611c8fSApple OSS Distributions static_assert(sizeof(FooShared) == sizeof(FooRaw)); 116bb611c8fSApple OSS Distributions static_assert(alignof(FooShared) == alignof(FooRaw)); 117bb611c8fSApple OSS Distributions static_assert(offsetof(FooShared, ptr) == offsetof(FooRaw, ptr)); 118bb611c8fSApple OSS Distributions } 119bb611c8fSApple OSS Distributions 120bb611c8fSApple OSS Distributions namespace ns7 { 121bb611c8fSApple OSS Distributions struct FooShared { 122bb611c8fSApple OSS Distributions char c; 123bb611c8fSApple OSS Distributions unsigned int b : 5; 124bb611c8fSApple OSS Distributions test_shared_ptr<int> ptr __attribute__((packed)); 125bb611c8fSApple OSS Distributions int i; 126bb611c8fSApple OSS Distributions }; 127bb611c8fSApple OSS Distributions 128bb611c8fSApple OSS Distributions struct FooRaw { 129bb611c8fSApple OSS Distributions char c; 130bb611c8fSApple OSS Distributions unsigned int b : 5; 131bb611c8fSApple OSS Distributions int* ptr __attribute__((packed)); 132bb611c8fSApple OSS Distributions int i; 133bb611c8fSApple OSS Distributions }; 134bb611c8fSApple OSS Distributions 135bb611c8fSApple OSS Distributions static_assert(sizeof(FooShared) == sizeof(FooRaw)); 136bb611c8fSApple OSS Distributions static_assert(alignof(FooShared) == alignof(FooRaw)); 137bb611c8fSApple OSS Distributions static_assert(offsetof(FooShared, ptr) == offsetof(FooRaw, ptr)); 138bb611c8fSApple OSS Distributions } 139bb611c8fSApple OSS Distributions 140*8d741a5dSApple OSS Distributions T_DECL(abi_size_alignment, "intrusive_shared_ptr.abi.size_alignment", T_META_TAG_VM_PREFERRED) { 141bb611c8fSApple OSS Distributions T_PASS("intrusive_shared_ptr.abi.size_alignment compile-time tests passed"); 142bb611c8fSApple OSS Distributions } 143