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