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