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