1 // REQUIRES: aarch64-registered-target
2 // RUN: %clang_cc1 -triple aarch64-linux-gnu -x c++ -std=c++1z %s -verify
3 // expected-no-diagnostics
4 
5 #include <stddef.h>
6 
7 struct t1
8 {
9   int foo : 1;
10   char : 0;
11   char bar;
12 
13 };
14 static_assert(offsetof(struct t1, bar) == 1);
15 static_assert(sizeof(struct t1) == 4);
16 
17 struct t2
18 {
19   int foo : 1;
20   short : 0;
21   char bar;
22 };
23 static_assert(offsetof(struct t2, bar) == 2);
24 static_assert(sizeof(struct t2) == 4);
25 
26 struct t3
27 {
28   int foo : 1;
29   int : 0;
30   char bar;
31 };
32 static_assert(offsetof(struct t3, bar) == 4);
33 static_assert(sizeof(struct t3) == 8);
34 
35 struct t4
36 {
37   int foo : 1;
38   long : 0;
39   char bar;
40 };
41 static_assert(offsetof(struct t4, bar) == 8);
42 static_assert(sizeof(struct t4) == 16);
43 
44 struct t5
45 {
46   int foo : 1;
47   long long : 0;
48   char bar;
49 };
50 static_assert(offsetof(struct t5, bar) == 8);
51 static_assert(sizeof(struct t5) == 16);
52 
53 struct t6
54 {
55   int foo : 1;
56   char : 0;
57   char bar : 1;
58   char bar2;
59 };
60 static_assert(offsetof(struct t6, bar2) == 2);
61 static_assert(sizeof(struct t6) == 4);
62 
63 struct t7
64 {
65   int foo : 1;
66   short : 0;
67   char bar1 : 1;
68   char bar2;
69 };
70 static_assert(offsetof(struct t7, bar2) == 3);
71 static_assert(sizeof(struct t7) == 4);
72 
73 struct t8
74 {
75   int foo : 1;
76   int : 0;
77   char bar1 : 1;
78   char bar2;
79 };
80 static_assert(offsetof(struct t8, bar2) == 5);
81 static_assert(sizeof(struct t8) == 8);
82 
83 struct t9
84 {
85   int foo : 1;
86   long : 0;
87   char bar1 : 1;
88   char bar2;
89 };
90 static_assert(offsetof(struct t9, bar2) == 9);
91 static_assert(sizeof(struct t9) == 16);
92 
93 struct t10
94 {
95   int foo : 1;
96   long long : 0;
97   char bar1 : 1;
98   char bar2;
99 };
100 static_assert(offsetof(struct t10, bar2) == 9);
101 static_assert(sizeof(struct t10) == 16);
102 
103 struct t11
104 {
105   int foo : 1;
106   long long : 0;
107   char : 0;
108   char bar1 : 1;
109   char bar2;
110 };
111 static_assert(offsetof(struct t11, bar2) == 9);
112 static_assert(sizeof(struct t11) == 16);
113 
114 struct t12
115 {
116   int foo : 1;
117   char : 0;
118   long long : 0;
119   char : 0;
120   char bar;
121 };
122 static_assert(offsetof(struct t12, bar) == 8);
123 static_assert(sizeof(struct t12) == 16);
124 
125 struct t13
126 {
127   char foo;
128   long : 0;
129   char bar;
130 };
131 static_assert(offsetof(struct t13, bar) == 8);
132 static_assert(sizeof(struct t13) == 16);
133 
134 struct t14
135 {
136   char foo1;
137   int : 0;
138   char foo2 : 1;
139   short foo3 : 16;
140   char : 0;
141   short foo4 : 16;
142   char bar1;
143   int : 0;
144   char bar2;
145 };
146 static_assert(offsetof(struct t14, bar1) == 10);
147 static_assert(offsetof(struct t14, bar2) == 12);
148 static_assert(sizeof(struct t14) == 16);
149 
150 struct t15
151 {
152   char foo;
153   char : 0;
154   int : 0;
155   char bar;
156   long : 0;
157   char : 0;
158 };
159 static_assert(offsetof(struct t15, bar) == 4);
160 static_assert(sizeof(struct t15) == 8);
161 
162 struct t16
163 {
164   long : 0;
165   char bar;
166 };
167 static_assert(offsetof(struct t16, bar) == 0);
168 static_assert(sizeof(struct t16) == 8);
169 
170 struct t17
171 {
172   char foo;
173   long : 0;
174   long : 0;
175   char : 0;
176   char bar;
177 };
178 static_assert(offsetof(struct t17, bar) == 8);
179 static_assert(sizeof(struct t17) == 16);
180 
181 struct t18
182 {
183   long : 0;
184   long : 0;
185   char : 0;
186 };
187 static_assert(sizeof(struct t18) == 8);
188 
189 struct t19
190 {
191   char foo1;
192   long foo2 : 1;
193   char : 0;
194   long foo3 : 32;
195   char bar;
196 };
197 static_assert(offsetof(struct t19, bar) == 6);
198 static_assert(sizeof(struct t19) == 8);
199 
200 struct t20
201 {
202   short : 0;
203   int foo : 1;
204   long : 0;
205   char bar;
206 };
207 static_assert(offsetof(struct t20, bar) == 8);
208 static_assert(sizeof(struct t20) == 16);
209 
210 struct t21
211 {
212   short : 0;
213   int foo1 : 1;
214   char : 0;
215   int foo2 : 16;
216   long : 0;
217   char bar1;
218   int bar2;
219   long bar3;
220   char foo3 : 8;
221   char : 0;
222   long : 0;
223   int foo4 : 32;
224   short foo5: 1;
225   long bar4;
226   short foo6: 16;
227   short foo7: 16;
228   short foo8: 16;
229 };
230 static_assert(offsetof(struct t21, bar1) == 8);
231 static_assert(offsetof(struct t21, bar2) == 12);
232 static_assert(offsetof(struct t21, bar3) == 16);
233 static_assert(offsetof(struct t21, bar4) == 40);
234 static_assert(sizeof(struct t21) == 56);
235 
236 // The rules also apply to anonymous bitfields with non-zero length.
237 struct t22
238 {
239   char foo;
240   short :2;
241   char bar;
242 };
243 static_assert(alignof(struct t22) == 2);
244 static_assert(offsetof(struct t22, bar) == 2);
245 
main()246 int main() {
247   return 0;
248 }
249 
250