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