[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / Sema / ms_bitfield_layout.c
blob8d377bc28d496ca0be61e82a57a6e621e11e24da
1 // RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple i686-pc-win32 -fms-extensions -fdump-record-layouts %s 2>/dev/null \
2 // RUN: | FileCheck %s
3 // RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple x86_64-pc-win32 -fms-extensions -fdump-record-layouts %s 2>/dev/null \
4 // RUN: | FileCheck %s
6 typedef struct A {
7 char x;
8 int a : 22;
9 int : 0;
10 int c : 10;
11 char b : 3;
12 char d: 4;
13 short y;
14 } A;
16 // CHECK:*** Dumping AST Record Layout
17 // CHECK-NEXT: 0 | struct A
18 // CHECK-NEXT: 0 | char x
19 // CHECK-NEXT: 4:0-21 | int a
20 // CHECK-NEXT: 8:- | int
21 // CHECK-NEXT: 8:0-9 | int c
22 // CHECK-NEXT: 12:0-2 | char b
23 // CHECK-NEXT: 12:3-6 | char d
24 // CHECK-NEXT: 14 | short y
25 // CHECK-NEXT: | [sizeof=16, align=4]
27 typedef struct B {
28 char x;
29 int : 0;
30 short a : 4;
31 char y;
32 } B;
34 // CHECK:*** Dumping AST Record Layout
35 // CHECK-NEXT: 0 | struct B
36 // CHECK-NEXT: 0 | char x
37 // CHECK-NEXT: 1:- | int
38 // CHECK-NEXT: 2:0-3 | short a
39 // CHECK-NEXT: 4 | char y
40 // CHECK-NEXT: | [sizeof=6, align=2]
42 typedef struct C {
43 char x;
44 short a : 4;
45 int : 0;
46 char y;
47 } C;
49 // CHECK:*** Dumping AST Record Layout
50 // CHECK-NEXT: 0 | struct C
51 // CHECK-NEXT: 0 | char x
52 // CHECK-NEXT: 2:0-3 | short a
53 // CHECK-NEXT: 4:- | int
54 // CHECK-NEXT: 4 | char y
55 // CHECK-NEXT: | [sizeof=8, align=4]
57 typedef struct D {
58 char x;
59 short : 0;
60 int : 0;
61 char y;
62 } D;
64 // CHECK:*** Dumping AST Record Layout
65 // CHECK-NEXT: 0 | struct D
66 // CHECK-NEXT: 0 | char x
67 // CHECK-NEXT: 1:- | short
68 // CHECK-NEXT: 1:- | int
69 // CHECK-NEXT: 1 | char y
70 // CHECK-NEXT: | [sizeof=2, align=1]
72 typedef union E {
73 char x;
74 long long a : 3;
75 int b : 3;
76 long long : 0;
77 short y;
78 } E;
81 // CHECK:*** Dumping AST Record Layout
82 // CHECK-NEXT: 0 | union E
83 // CHECK-NEXT: 0 | char x
84 // CHECK-NEXT: 0:0-2 | long long a
85 // CHECK-NEXT: 0:0-2 | int b
86 // CHECK-NEXT: 0:- | long long
87 // CHECK-NEXT: 0 | short
88 // CHECK-NEXT: | [sizeof=8, align=2]
90 typedef struct F {
91 char x;
92 char a : 3;
93 char b : 3;
94 char c : 3;
95 short d : 6;
96 short e : 6;
97 short f : 6;
98 short g : 11;
99 short h : 11;
100 short i : 11;
101 short y;
102 } F;
104 // CHECK:*** Dumping AST Record Layout
105 // CHECK-NEXT: 0 | struct F
106 // CHECK-NEXT: 0 | char x
107 // CHECK-NEXT: 1:0-2 | char a
108 // CHECK-NEXT: 1:3-5 | char b
109 // CHECK-NEXT: 2:0-2 | char c
110 // CHECK-NEXT: 4:0-5 | short d
111 // CHECK-NEXT: 4:6-11 | short e
112 // CHECK-NEXT: 6:0-5 | short f
113 // CHECK-NEXT: 8:0-10 | short g
114 // CHECK-NEXT:10:0-10 | short h
115 // CHECK-NEXT:12:0-10 | short i
116 // CHECK-NEXT: 14 | short y
117 // CHECK-NEXT: | [sizeof=16, align=2]
119 typedef union G {
120 char x;
121 int a : 3;
122 int : 0;
123 long long : 0;
124 short y;
125 } G;
127 // CHECK:*** Dumping AST Record Layout
128 // CHECK-NEXT: 0 | union G
129 // CHECK-NEXT: 0 | char x
130 // CHECK-NEXT: 0:0-2 | int a
131 // CHECK-NEXT: 0:- | int
132 // CHECK-NEXT: 0:- | long long
133 // CHECK-NEXT: 0 | short y
134 // CHECK-NEXT: | [sizeof=4, align=2]
136 typedef struct H {
137 unsigned short a : 1;
138 unsigned char : 0;
139 unsigned long : 0;
140 unsigned short c : 1;
141 } H;
143 // CHECK:*** Dumping AST Record Layout
144 // CHECK-NEXT: 0 | struct H
145 // CHECK-NEXT: 0:0-0 | unsigned short a
146 // CHECK-NEXT: 2:- | unsigned char
147 // CHECK-NEXT: 2:- | unsigned long
148 // CHECK-NEXT: 2:0-0 | unsigned short c
149 // CHECK-NEXT: | [sizeof=4, align=2]
151 typedef struct I {
152 short : 8;
153 __declspec(align(16)) short : 8;
154 } I;
157 // CHECK:*** Dumping AST Record Layout
158 // CHECK-NEXT: 0 | struct I
159 // CHECK-NEXT: 0:0-7 | short
160 // CHECK-NEXT: 1:0-7 | short
161 // CHECK-NEXT: | [sizeof=2, align=2]
163 #pragma pack(push, 1)
165 typedef struct A1 {
166 char x;
167 int a : 22;
168 int : 0;
169 int c : 10;
170 char b : 3;
171 char d: 4;
172 short y;
173 } A1;
175 // CHECK:*** Dumping AST Record Layout
176 // CHECK-NEXT: 0 | struct A1
177 // CHECK-NEXT: 0 | char x
178 // CHECK-NEXT: 1:0-21 | int a
179 // CHECK-NEXT: 5:- | int
180 // CHECK-NEXT: 5:0-9 | int c
181 // CHECK-NEXT: 9:0-2 | char b
182 // CHECK-NEXT: 9:3-6 | char d
183 // CHECK-NEXT: 10 | short y
184 // CHECK-NEXT: | [sizeof=12, align=1]
186 typedef struct B1 {
187 char x;
188 int : 0;
189 short a : 4;
190 char y;
191 } B1;
193 // CHECK:*** Dumping AST Record Layout
194 // CHECK-NEXT: 0 | struct B1
195 // CHECK-NEXT: 0 | char x
196 // CHECK-NEXT: 1:- | int
197 // CHECK-NEXT: 1:0-3 | short
198 // CHECK-NEXT: 3 | char y
199 // CHECK-NEXT: | [sizeof=4, align=1]
201 typedef struct C1 {
202 char x;
203 short a : 4;
204 int : 0;
205 char y;
206 } C1;
208 // CHECK:*** Dumping AST Record Layout
209 // CHECK-NEXT: 0 | struct C1
210 // CHECK-NEXT: 0 | char x
211 // CHECK-NEXT: 1:0-3 | short
212 // CHECK-NEXT: 3:- | int
213 // CHECK-NEXT: 3 | char y
214 // CHECK-NEXT: | [sizeof=4, align=1]
216 typedef struct D1 {
217 char x;
218 short : 0;
219 int : 0;
220 char y;
221 } D1;
223 // CHECK:*** Dumping AST Record Layout
224 // CHECK-NEXT: 0 | struct D1
225 // CHECK-NEXT: 0 | char x
226 // CHECK-NEXT: 1:- | short
227 // CHECK-NEXT: 1:- | int
228 // CHECK-NEXT: 1 | char y
229 // CHECK-NEXT: | [sizeof=2, align=1]
231 typedef union E1 {
232 char x;
233 long long a : 3;
234 int b : 3;
235 long long : 0;
236 short y;
237 } E1;
239 // CHECK:*** Dumping AST Record Layout
240 // CHECK-NEXT: 0 | union E1
241 // CHECK-NEXT: 0 | char x
242 // CHECK-NEXT: 0:0-2 | long long a
243 // CHECK-NEXT: 0:0-2 | int b
244 // CHECK-NEXT: 0:- | long long
245 // CHECK-NEXT: 0 | short y
246 // CHECK-NEXT: | [sizeof=8, align=1]
248 typedef struct F1 {
249 char x;
250 char a : 3;
251 char b : 3;
252 char c : 3;
253 short d : 6;
254 short e : 6;
255 short f : 6;
256 short g : 11;
257 short h : 11;
258 short i : 11;
259 short y;
260 } F1;
262 // CHECK:*** Dumping AST Record Layout
263 // CHECK-NEXT: 0 | struct F1
264 // CHECK-NEXT: 0 | char x
265 // CHECK-NEXT: 1:0-2 | char a
266 // CHECK-NEXT: 1:3-5 | char b
267 // CHECK-NEXT: 2:0-2 | char c
268 // CHECK-NEXT: 3:0-5 | short d
269 // CHECK-NEXT: 3:6-11 | short e
270 // CHECK-NEXT: 5:0-5 | short f
271 // CHECK-NEXT: 7:0-10 | short g
272 // CHECK-NEXT: 9:0-10 | short h
273 // CHECK-NEXT:11:0-10 | short i
274 // CHECK-NEXT: 13 | short y
275 // CHECK-NEXT: | [sizeof=15, align=1]
277 typedef union G1 {
278 char x;
279 int a : 3;
280 int : 0;
281 long long : 0;
282 short y;
283 } G1;
285 // CHECK:*** Dumping AST Record Layout
286 // CHECK-NEXT: 0 | union G1
287 // CHECK-NEXT: 0 | char x
288 // CHECK-NEXT: 0:0-2 | int a
289 // CHECK-NEXT: 0:- | int
290 // CHECK-NEXT: 0:- | long long
291 // CHECK-NEXT: 0 | short y
292 // CHECK-NEXT: | [sizeof=4, align=1]
294 typedef struct H1 {
295 unsigned long a : 1;
296 unsigned char : 0;
297 unsigned long : 0;
298 unsigned long c : 1;
299 } H1;
301 // CHECK:*** Dumping AST Record Layout
302 // CHECK-NEXT: 0 | struct H1
303 // CHECK-NEXT: 0:0-0 | unsigned long a
304 // CHECK-NEXT: 4:- | unsigned char
305 // CHECK-NEXT: 4:- | unsigned long
306 // CHECK-NEXT: 4:0-0 | unsigned long c
307 // CHECK-NEXT: | [sizeof=8, align=1]
309 typedef struct I1 {
310 short : 8;
311 __declspec(align(16)) short : 8;
312 } I1;
314 // CHECK:*** Dumping AST Record Layout
315 // CHECK-NEXT: 0 | struct I1
316 // CHECK-NEXT: 0:0-7 | short
317 // CHECK-NEXT: 1:0-7 | short
318 // CHECK-NEXT: | [sizeof=2, align=1]
320 #pragma pack(pop)
322 int x[
323 sizeof(A ) +
324 sizeof(B ) +
325 sizeof(C ) +
326 sizeof(D ) +
327 sizeof(E ) +
328 sizeof(F ) +
329 sizeof(G ) +
330 sizeof(H ) +
331 sizeof(I ) +
332 sizeof(A1) +
333 sizeof(B1) +
334 sizeof(C1) +
335 sizeof(D1) +
336 sizeof(E1) +
337 sizeof(F1) +
338 sizeof(G1) +
339 sizeof(H1) +
340 sizeof(I1) +