blob: 3f9452539408d69d5de7f1a4124a867cdf04537d [file] [log] [blame]
Chad Rosier4ab00242011-08-04 00:19:13 +00001// RUN: %clang_cc1 -target-abi apcs-gnu -triple armv7-apple-darwin10 %s -verify
Chad Rosier61a62212011-08-04 01:21:14 +00002//
3// Note: gcc forces the alignment to 4 bytes, regardless of the type of the
4// zero length bitfield.
5// rdar://9859156
Chad Rosier4ab00242011-08-04 00:19:13 +00006
7#include <stddef.h>
8
9struct t1
10{
11 int foo : 1;
12 char : 0;
13 char bar;
14};
Chad Rosier61a62212011-08-04 01:21:14 +000015static int arr1_offset[(offsetof(struct t1, bar) == 4) ? 0 : -1];
16static int arr1_sizeof[(sizeof(struct t1) == 8) ? 0 : -1];
Chad Rosier4ab00242011-08-04 00:19:13 +000017
18struct t2
19{
20 int foo : 1;
21 short : 0;
22 char bar;
23};
Chad Rosier61a62212011-08-04 01:21:14 +000024static int arr2_offset[(offsetof(struct t2, bar) == 4) ? 0 : -1];
25static int arr2_sizeof[(sizeof(struct t2) == 8) ? 0 : -1];
Chad Rosier4ab00242011-08-04 00:19:13 +000026
27struct t3
28{
29 int foo : 1;
30 int : 0;
31 char bar;
32};
Chad Rosier61a62212011-08-04 01:21:14 +000033static int arr3_offset[(offsetof(struct t3, bar) == 4) ? 0 : -1];
34static int arr3_sizeof[(sizeof(struct t3) == 8) ? 0 : -1];
Chad Rosier4ab00242011-08-04 00:19:13 +000035
36struct t4
37{
38 int foo : 1;
39 long : 0;
40 char bar;
41};
Chad Rosier61a62212011-08-04 01:21:14 +000042static int arr4_offset[(offsetof(struct t4, bar) == 4) ? 0 : -1];
43static int arr4_sizeof[(sizeof(struct t4) == 8) ? 0 : -1];
Chad Rosier4ab00242011-08-04 00:19:13 +000044
45struct t5
46{
47 int foo : 1;
48 long long : 0;
49 char bar;
50};
Chad Rosier61a62212011-08-04 01:21:14 +000051static int arr5_offset[(offsetof(struct t5, bar) == 4) ? 0 : -1];
52static int arr5_sizeof[(sizeof(struct t5) == 8) ? 0 : -1];
Chad Rosier4ab00242011-08-04 00:19:13 +000053
54struct t6
55{
56 int foo : 1;
57 char : 0;
58 char bar : 1;
59 char bar2;
60};
Chad Rosierb8fca902011-08-05 22:38:04 +000061static int arr6_offset[(offsetof(struct t6, bar2) == 5) ? 0 : -1];
62static int arr6_sizeof[(sizeof(struct t6) == 8) ? 0 : -1];
Chad Rosier4ab00242011-08-04 00:19:13 +000063
64struct t7
65{
66 int foo : 1;
67 short : 0;
68 char bar1 : 1;
69 char bar2;
70};
Chad Rosierb8fca902011-08-05 22:38:04 +000071static int arr7_offset[(offsetof(struct t7, bar2) == 5) ? 0 : -1];
72static int arr7_sizeof[(sizeof(struct t7) == 8) ? 0 : -1];
Chad Rosier4ab00242011-08-04 00:19:13 +000073
74struct t8
75{
76 int foo : 1;
77 int : 0;
78 char bar1 : 1;
79 char bar2;
80};
Chad Rosierb8fca902011-08-05 22:38:04 +000081static int arr8_offset[(offsetof(struct t8, bar2) == 5) ? 0 : -1];
82static int arr8_sizeof[(sizeof(struct t8) == 8) ? 0 : -1];
Chad Rosier4ab00242011-08-04 00:19:13 +000083
84struct t9
85{
86 int foo : 1;
87 long : 0;
88 char bar1 : 1;
89 char bar2;
90};
Chad Rosierb8fca902011-08-05 22:38:04 +000091static int arr9_offset[(offsetof(struct t9, bar2) == 5) ? 0 : -1];
92static int arr9_sizeof[(sizeof(struct t9) == 8) ? 0 : -1];
Chad Rosier4ab00242011-08-04 00:19:13 +000093
94struct t10
95{
96 int foo : 1;
97 long long : 0;
98 char bar1 : 1;
99 char bar2;
100};
Chad Rosierb8fca902011-08-05 22:38:04 +0000101static int arr10_offset[(offsetof(struct t10, bar2) == 5) ? 0 : -1];
102static int arr10_sizeof[(sizeof(struct t10) == 8) ? 0 : -1];
Chad Rosier4ab00242011-08-04 00:19:13 +0000103
104struct t11
105{
106 int foo : 1;
107 long long : 0;
108 char : 0;
109 char bar1 : 1;
110 char bar2;
111};
Chad Rosierb8fca902011-08-05 22:38:04 +0000112static int arr11_offset[(offsetof(struct t11, bar2) == 5) ? 0 : -1];
113static int arr11_sizeof[(sizeof(struct t11) == 8) ? 0 : -1];
Chad Rosier4ab00242011-08-04 00:19:13 +0000114
Chad Rosier61a62212011-08-04 01:21:14 +0000115struct t12
116{
117 int foo : 1;
118 char : 0;
119 long long : 0;
120 char : 0;
121 char bar;
122};
123static int arr12_offset[(offsetof(struct t12, bar) == 4) ? 0 : -1];
124static int arr12_sizeof[(sizeof(struct t12) == 8) ? 0 : -1];
125
Chad Rosierb8fca902011-08-05 22:38:04 +0000126struct t13
127{
128 char foo;
129 long : 0;
130 char bar;
131};
132static int arr13_offset[(offsetof(struct t13, bar) == 4) ? 0 : -1];
133static int arr13_sizeof[(sizeof(struct t13) == 8) ? 0 : -1];
134
135struct t14
136{
137 char foo1;
138 int : 0;
139 char foo2 : 1;
140 short foo3 : 16;
141 char : 0;
142 short foo4 : 16;
143 char bar1;
144 int : 0;
145 char bar2;
146};
147static int arr14_bar1_offset[(offsetof(struct t14, bar1) == 10) ? 0 : -1];
148static int arr14_bar2_offset[(offsetof(struct t14, bar2) == 12) ? 0 : -1];
149static int arr14_sizeof[(sizeof(struct t14) == 16) ? 0 : -1];
150
151struct t15
152{
153 char foo;
154 char : 0;
155 int : 0;
156 char bar;
157 long : 0;
158 char : 0;
159};
160static int arr15_offset[(offsetof(struct t15, bar) == 4) ? 0 : -1];
161static int arr15_sizeof[(sizeof(struct t15) == 8) ? 0 : -1];
162
163struct t16
164{
165 long : 0;
166 char bar;
167};
168static int arr16_offset[(offsetof(struct t16, bar) == 0) ? 0 : -1];
169static int arr16_sizeof[(sizeof(struct t16) == 4) ? 0 : -1];
170
171struct t17
172{
173 char foo;
174 long : 0;
175 long : 0;
176 char : 0;
177 char bar;
178};
179static int arr17_offset[(offsetof(struct t17, bar) == 4) ? 0 : -1];
180static int arr17_sizeof[(sizeof(struct t17) == 8) ? 0 : -1];
181
182struct t18
183{
184 long : 0;
185 long : 0;
186 char : 0;
187};
188static int arr18_sizeof[(sizeof(struct t18) == 0) ? 0 : -1];
189
190struct t19
191{
192 char foo1;
193 long foo2 : 1;
194 char : 0;
195 long foo3 : 32;
196 char bar;
197};
198static int arr19_offset[(offsetof(struct t19, bar) == 8) ? 0 : -1];
199static int arr19_sizeof[(sizeof(struct t19) == 12) ? 0 : -1];
200
201struct t20
202{
203 short : 0;
204 int foo : 1;
205 long : 0;
206 char bar;
207};
208static int arr20_offset[(offsetof(struct t20, bar) == 4) ? 0 : -1];
209static int arr20_sizeof[(sizeof(struct t20) == 8) ? 0 : -1];
210
211struct t21
212{
213 short : 0;
214 int foo1 : 1;
215 char : 0;
216 int foo2 : 16;
217 long : 0;
218 char bar1;
219 int bar2;
220 long bar3;
221 char foo3 : 8;
222 char : 0;
223 long : 0;
224 int foo4 : 32;
225 short foo5: 1;
226 long bar4;
227 short foo6: 16;
228 short foo7: 16;
229 short foo8: 16;
230};
231static int arr21_bar1_offset[(offsetof(struct t21, bar1) == 8) ? 0 : -1];
232static int arr21_bar2_offset[(offsetof(struct t21, bar2) == 12) ? 0 : -1];
233static int arr21_bar3_offset[(offsetof(struct t21, bar3) == 16) ? 0 : -1];
234static int arr21_bar4_offset[(offsetof(struct t21, bar4) == 32) ? 0 : -1];
235static int arr21_sizeof[(sizeof(struct t21) == 44) ? 0 : -1];
236
Chad Rosier4ab00242011-08-04 00:19:13 +0000237int main() {
238 return 0;
239}
240