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