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