[clang][lex] NFCI: Use DirectoryEntryRef in ModuleMap::inferFrameworkModule()
[llvm-project.git] / clang / test / Layout / aix-double-struct-member.cpp
blob6e091fcb1b1e1429b59a4873897947df4c8c0800
1 // RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -fdump-record-layouts \
2 // RUN: -fsyntax-only -fxl-pragma-pack %s | \
3 // RUN: FileCheck %s
5 // RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -fdump-record-layouts \
6 // RUN: -fsyntax-only -fxl-pragma-pack %s | \
7 // RUN: FileCheck %s
9 namespace test1 {
10 // Test the class layout when having a double which is/is not the first struct
11 // member.
12 struct D {
13 double d1;
14 int i1;
17 struct DoubleFirst {
18 struct D d2;
19 int i2;
22 struct IntFirst {
23 int i3;
24 struct D d3;
27 int a = sizeof(DoubleFirst);
28 int b = sizeof(IntFirst);
30 // CHECK: *** Dumping AST Record Layout
31 // CHECK-NEXT: 0 | struct test1::D
32 // CHECK-NEXT: 0 | double d1
33 // CHECK-NEXT: 8 | int i1
34 // CHECK-NEXT: | [sizeof=16, dsize=16, align=4, preferredalign=8,
35 // CHECK-NEXT: | nvsize=16, nvalign=4, preferrednvalign=8]
37 // CHECK: *** Dumping AST Record Layout
38 // CHECK-NEXT: 0 | struct test1::DoubleFirst
39 // CHECK-NEXT: 0 | struct test1::D d2
40 // CHECK-NEXT: 0 | double d1
41 // CHECK-NEXT: 8 | int i1
42 // CHECK-NEXT: 16 | int i2
43 // CHECK-NEXT: | [sizeof=24, dsize=24, align=4, preferredalign=8,
44 // CHECK-NEXT: | nvsize=24, nvalign=4, preferrednvalign=8]
46 // CHECK: *** Dumping AST Record Layout
47 // CHECK-NEXT: 0 | struct test1::IntFirst
48 // CHECK-NEXT: 0 | int i3
49 // CHECK-NEXT: 4 | struct test1::D d3
50 // CHECK-NEXT: 4 | double d1
51 // CHECK-NEXT: 12 | int i1
52 // CHECK-NEXT: | [sizeof=20, dsize=20, align=4, preferredalign=4,
53 // CHECK-NEXT: | nvsize=20, nvalign=4, preferrednvalign=4]
54 } // namespace test1
56 namespace test2 {
57 // Test the class layout when having a zero-sized bitfield followed by double.
58 struct Double {
59 int : 0;
60 double d;
63 int a = sizeof(Double);
65 // CHECK: *** Dumping AST Record Layout
66 // CHECK-NEXT: 0 | struct test2::Double
67 // CHECK-NEXT: 0:- | int
68 // CHECK-NEXT: 0 | double d
69 // CHECK-NEXT: | [sizeof=8, dsize=8, align=4, preferredalign=4,
70 // CHECK-NEXT: | nvsize=8, nvalign=4, preferrednvalign=4]
71 } // namespace test2
73 namespace test3 {
74 // Test the class layout when having a double member in union.
75 union A {
76 int b;
77 double d;
80 struct UnionStruct {
81 union A a;
82 int i;
85 int a = sizeof(UnionStruct);
87 // CHECK: *** Dumping AST Record Layout
88 // CHECK-NEXT: 0 | union test3::A
89 // CHECK-NEXT: 0 | int b
90 // CHECK-NEXT: 0 | double d
91 // CHECK-NEXT: | [sizeof=8, dsize=8, align=4, preferredalign=8,
92 // CHECK-NEXT: | nvsize=8, nvalign=4, preferrednvalign=8]
94 // CHECK: *** Dumping AST Record Layout
95 // CHECK-NEXT: 0 | struct test3::UnionStruct
96 // CHECK-NEXT: 0 | union test3::A a
97 // CHECK-NEXT: 0 | int b
98 // CHECK-NEXT: 0 | double d
99 // CHECK-NEXT: 8 | int i
100 // CHECK-NEXT: | [sizeof=16, dsize=16, align=4, preferredalign=8,
101 // CHECK-NEXT: | nvsize=16, nvalign=4, preferrednvalign=8]
103 } // namespace test3
105 namespace test4 {
106 // Test the class layout when having multiple base classes.
107 struct A {
108 int a;
111 struct B {
112 double d;
115 class S : A, B {
118 int a = sizeof(S);
120 // CHECK: *** Dumping AST Record Layout
121 // CHECK-NEXT: 0 | struct test4::A
122 // CHECK-NEXT: 0 | int a
123 // CHECK-NEXT: | [sizeof=4, dsize=4, align=4, preferredalign=4,
124 // CHECK-NEXT: | nvsize=4, nvalign=4, preferrednvalign=4]
126 // CHECK: *** Dumping AST Record Layout
127 // CHECK-NEXT: 0 | struct test4::B
128 // CHECK-NEXT: 0 | double d
129 // CHECK-NEXT: | [sizeof=8, dsize=8, align=4, preferredalign=8,
130 // CHECK-NEXT: | nvsize=8, nvalign=4, preferrednvalign=8]
132 // CHECK: *** Dumping AST Record Layout
133 // CHECK-NEXT: 0 | class test4::S
134 // CHECK-NEXT: 0 | struct test4::A (base)
135 // CHECK-NEXT: 0 | int a
136 // CHECK-NEXT: 4 | struct test4::B (base)
137 // CHECK-NEXT: 4 | double d
138 // CHECK-NEXT: | [sizeof=12, dsize=12, align=4, preferredalign=4,
139 // CHECK-NEXT: | nvsize=12, nvalign=4, preferrednvalign=4]
140 } // namespace test4
142 namespace test5 {
143 struct Empty {
146 struct EmptyDer : Empty {
147 double d;
150 struct NonEmpty {
151 int i;
154 struct NonEmptyDer : NonEmpty {
155 double d;
158 int a = sizeof(EmptyDer);
159 int b = sizeof(NonEmptyDer);
161 // CHECK: *** Dumping AST Record Layout
162 // CHECK-NEXT: 0 | struct test5::Empty (empty)
163 // CHECK-NEXT: | [sizeof=1, dsize=1, align=1, preferredalign=1,
164 // CHECK-NEXT: | nvsize=1, nvalign=1, preferrednvalign=1]
166 // CHECK: *** Dumping AST Record Layout
167 // CHECK-NEXT: 0 | struct test5::EmptyDer
168 // CHECK-NEXT: 0 | struct test5::Empty (base) (empty)
169 // CHECK-NEXT: 0 | double d
170 // CHECK-NEXT: | [sizeof=8, dsize=8, align=4, preferredalign=8,
171 // CHECK-NEXT: | nvsize=8, nvalign=4, preferrednvalign=8]
173 // CHECK: *** Dumping AST Record Layout
174 // CHECK-NEXT: 0 | struct test5::NonEmpty
175 // CHECK-NEXT: 0 | int i
176 // CHECK-NEXT: | [sizeof=4, dsize=4, align=4, preferredalign=4,
177 // CHECK-NEXT: | nvsize=4, nvalign=4, preferrednvalign=4]
179 // CHECK: *** Dumping AST Record Layout
180 // CHECK-NEXT: 0 | struct test5::NonEmptyDer
181 // CHECK-NEXT: 0 | struct test5::NonEmpty (base)
182 // CHECK-NEXT: 0 | int i
183 // CHECK-NEXT: 4 | double d
184 // CHECK-NEXT: | [sizeof=12, dsize=12, align=4, preferredalign=4,
185 // CHECK-NEXT: | nvsize=12, nvalign=4, preferrednvalign=4]
186 } // namespace test5
188 namespace test6 {
189 struct A {
190 struct B {
191 double d[3];
192 } b;
195 int a = sizeof(A);
197 // CHECK: *** Dumping AST Record Layout
198 // CHECK-NEXT: 0 | struct test6::A::B
199 // CHECK-NEXT: 0 | double[3] d
200 // CHECK-NEXT: | [sizeof=24, dsize=24, align=4, preferredalign=8,
201 // CHECK-NEXT: | nvsize=24, nvalign=4, preferrednvalign=8]
203 // CHECK: *** Dumping AST Record Layout
204 // CHECK-NEXT: 0 | struct test6::A
205 // CHECK-NEXT: 0 | struct test6::A::B b
206 // CHECK-NEXT: 0 | double[3] d
207 // CHECK-NEXT: | [sizeof=24, dsize=24, align=4, preferredalign=8,
208 // CHECK-NEXT: | nvsize=24, nvalign=4, preferrednvalign=8]
210 } // namespace test6
212 namespace test7 {
213 struct A {
214 struct B {
215 long double _Complex d[3];
216 } b;
219 int a = sizeof(A);
221 // CHECK: *** Dumping AST Record Layout
222 // CHECK-NEXT: 0 | struct test7::A::B
223 // CHECK-NEXT: 0 | _Complex long double[3] d
224 // CHECK-NEXT: | [sizeof=48, dsize=48, align=4, preferredalign=8,
225 // CHECK-NEXT: | nvsize=48, nvalign=4, preferrednvalign=8]
227 // CHECK: *** Dumping AST Record Layout
228 // CHECK-NEXT: 0 | struct test7::A
229 // CHECK-NEXT: 0 | struct test7::A::B b
230 // CHECK-NEXT: 0 | _Complex long double[3] d
231 // CHECK-NEXT: | [sizeof=48, dsize=48, align=4, preferredalign=8,
232 // CHECK-NEXT: | nvsize=48, nvalign=4, preferrednvalign=8]
234 } // namespace test7
236 namespace test8 {
237 struct Emp {};
239 struct Y : Emp {
240 double d;
243 struct Z : Emp {
244 Y y;
247 int a = sizeof(Z);
249 // CHECK: *** Dumping AST Record Layout
250 // CHECK-NEXT: 0 | struct test8::Emp (empty)
251 // CHECK-NEXT: | [sizeof=1, dsize=1, align=1, preferredalign=1,
252 // CHECK-NEXT: | nvsize=1, nvalign=1, preferrednvalign=1]
254 // CHECK: *** Dumping AST Record Layout
255 // CHECK-NEXT: 0 | struct test8::Y
256 // CHECK-NEXT: 0 | struct test8::Emp (base) (empty)
257 // CHECK-NEXT: 0 | double d
258 // CHECK-NEXT: | [sizeof=8, dsize=8, align=4, preferredalign=8,
259 // CHECK-NEXT: | nvsize=8, nvalign=4, preferrednvalign=8]
261 // CHECK: *** Dumping AST Record Layout
262 // CHECK-NEXT: 0 | struct test8::Z
263 // CHECK-NEXT: 0 | struct test8::Emp (base) (empty)
264 // CHECK-NEXT: 8 | struct test8::Y y
265 // CHECK-NEXT: 8 | struct test8::Emp (base) (empty)
266 // CHECK-NEXT: 8 | double d
267 // CHECK-NEXT: | [sizeof=16, dsize=16, align=4, preferredalign=8,
268 // CHECK-NEXT: | nvsize=16, nvalign=4, preferrednvalign=8]
270 } // namespace test8
272 namespace test9 {
273 // Test the class layout when having a zero-extent array in a base class, which
274 // renders the base class not empty.
275 struct A { char zea[0]; };
277 struct B : A { double d; };
279 struct C { double d; };
280 struct D : A, C { char x; };
282 int a = sizeof(B);
283 int b = sizeof(D);
285 // CHECK: 0 | struct test9::B
286 // CHECK-NEXT: 0 | struct test9::A (base)
287 // CHECK-NEXT: 0 | char[0] zea
288 // CHECK-NEXT: 0 | double d
289 // CHECK-NEXT: | [sizeof=8, dsize=8, align=4, preferredalign=4,
290 // CHECK-NEXT: | nvsize=8, nvalign=4, preferrednvalign=4]
292 // CHECK: 0 | struct test9::D
293 // CHECK-NEXT: 0 | struct test9::A (base)
294 // CHECK-NEXT: 0 | char[0] zea
295 // CHECK-NEXT: 0 | struct test9::C (base)
296 // CHECK-NEXT: 0 | double d
297 // CHECK-NEXT: 8 | char x
298 // CHECK-NEXT: | [sizeof=12, dsize=9, align=4, preferredalign=4,
299 // CHECK-NEXT: | nvsize=9, nvalign=4, preferrednvalign=4]
301 } // namespace test9
303 namespace test10 {
304 struct A { double x; };
305 struct B : A {};
307 int a = sizeof(B);
309 // CHECK: 0 | struct test10::B
310 // CHECK-NEXT: 0 | struct test10::A (base)
311 // CHECK-NEXT: 0 | double x
312 // CHECK-NEXT: | [sizeof=8, dsize=8, align=4, preferredalign=8,
313 // CHECK-NEXT: | nvsize=8, nvalign=4, preferrednvalign=8]
315 } // namespace test10
317 namespace test11 {
318 // Test how #pragma pack and align attribute interacts with AIX `power`
319 // alignment rules.
320 struct A {
321 char a;
322 double __attribute__((aligned(16))) d;
323 int i;
326 struct B {
327 double __attribute__((aligned(4))) d1;
328 char a;
329 double d2;
332 #pragma pack(2)
333 struct C {
334 int i;
335 short j;
336 double k;
338 #pragma pack(pop)
340 #pragma pack(2)
341 struct D {
342 double d;
343 short j;
344 int i;
346 #pragma pack(pop)
348 #pragma pack(8)
349 struct E {
350 double __attribute__((aligned(4))) d;
351 short s;
353 #pragma pack(pop)
355 #pragma pack(4)
356 struct F : public D {
357 double d;
359 #pragma pack(pop)
361 #pragma pack(2)
362 struct G : public E {
363 int i;
365 #pragma pack(pop)
367 int a = sizeof(A);
368 int b = sizeof(B);
369 int c = sizeof(C);
370 int d = sizeof(D);
371 int e = sizeof(E);
372 int f = sizeof(F);
373 int g = sizeof(G);
375 // CHECK: *** Dumping AST Record Layout
376 // CHECK-NEXT: 0 | struct test11::A
377 // CHECK-NEXT: 0 | char a
378 // CHECK-NEXT: 16 | double d
379 // CHECK-NEXT: 24 | int i
380 // CHECK-NEXT: | [sizeof=32, dsize=32, align=16, preferredalign=16,
381 // CHECK-NEXT: | nvsize=32, nvalign=16, preferrednvalign=16]
383 // CHECK: *** Dumping AST Record Layout
384 // CHECK-NEXT: 0 | struct test11::B
385 // CHECK-NEXT: 0 | double d1
386 // CHECK-NEXT: 8 | char a
387 // CHECK-NEXT: 12 | double d2
388 // CHECK-NEXT: | [sizeof=24, dsize=24, align=4, preferredalign=8,
389 // CHECK-NEXT: | nvsize=24, nvalign=4, preferrednvalign=8]
391 // CHECK: *** Dumping AST Record Layout
392 // CHECK-NEXT: 0 | struct test11::C
393 // CHECK-NEXT: 0 | int i
394 // CHECK-NEXT: 4 | short j
395 // CHECK-NEXT: 6 | double k
396 // CHECK-NEXT: | [sizeof=14, dsize=14, align=2, preferredalign=2,
397 // CHECK-NEXT: | nvsize=14, nvalign=2, preferrednvalign=2]
399 // CHECK: *** Dumping AST Record Layout
400 // CHECK-NEXT: 0 | struct test11::D
401 // CHECK-NEXT: 0 | double d
402 // CHECK-NEXT: 8 | short j
403 // CHECK-NEXT: 10 | int i
404 // CHECK-NEXT: | [sizeof=14, dsize=14, align=2, preferredalign=2,
405 // CHECK-NEXT: | nvsize=14, nvalign=2, preferrednvalign=2]
407 // CHECK: *** Dumping AST Record Layout
408 // CHECK-NEXT: 0 | struct test11::E
409 // CHECK-NEXT: 0 | double d
410 // CHECK-NEXT: 8 | short s
411 // CHECK-NEXT: | [sizeof=16, dsize=16, align=4, preferredalign=8,
412 // CHECK-NEXT: | nvsize=16, nvalign=4, preferrednvalign=8]
414 // CHECK: *** Dumping AST Record Layout
415 // CHECK-NEXT: 0 | struct test11::F
416 // CHECK-NEXT: 0 | struct test11::D (base)
417 // CHECK-NEXT: 0 | double d
418 // CHECK-NEXT: 8 | short j
419 // CHECK-NEXT: 10 | int i
420 // CHECK-NEXT: 16 | double d
421 // CHECK-NEXT: | [sizeof=24, dsize=24, align=4, preferredalign=4,
422 // CHECK-NEXT: | nvsize=24, nvalign=4, preferrednvalign=4]
424 // CHECK: *** Dumping AST Record Layout
425 // CHECK-NEXT: 0 | struct test11::G
426 // CHECK-NEXT: 0 | struct test11::E (base)
427 // CHECK-NEXT: 0 | double d
428 // CHECK-NEXT: 8 | short s
429 // CHECK-NEXT: 16 | int i
430 // CHECK-NEXT: | [sizeof=20, dsize=20, align=2, preferredalign=2,
431 // CHECK-NEXT: | nvsize=20, nvalign=2, preferrednvalign=2]
433 } // namespace test11