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