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