1 | // RUN: %clang_cc1 -w -fdump-record-layouts-simple %s > %t.layouts |
2 | // RUN: %clang_cc1 -w -fdump-record-layouts-simple %s > %t.before |
3 | // RUN: %clang_cc1 -w -DPACKED= -DALIGNED16= -fdump-record-layouts-simple -foverride-record-layout=%t.layouts %s > %t.after |
4 | // RUN: diff -u %t.before %t.after |
5 | // RUN: FileCheck %s < %t.after |
6 | |
7 | // If not explicitly disabled, set PACKED to the packed attribute. |
8 | #ifndef PACKED |
9 | # define PACKED __attribute__((packed)) |
10 | #endif |
11 | |
12 | struct Empty1 { }; |
13 | struct Empty2 { }; |
14 | |
15 | // CHECK: Type: struct X0 |
16 | struct X0 : public Empty1 { |
17 | int x[6] PACKED; |
18 | }; |
19 | |
20 | // CHECK: Type: struct X1 |
21 | struct X1 : public X0, public Empty2 { |
22 | char x[13]; |
23 | struct X0 y; |
24 | } PACKED; |
25 | |
26 | // CHECK: Type: struct X2 |
27 | struct PACKED X2 : public X1, public X0, public Empty1 { |
28 | short x; |
29 | int y; |
30 | }; |
31 | |
32 | // CHECK: Type: struct X3 |
33 | struct PACKED X3 : virtual public X1, public X0 { |
34 | short x; |
35 | int y; |
36 | }; |
37 | |
38 | // CHECK: Type: struct X4 |
39 | struct PACKED X4 { |
40 | unsigned int a : 1; |
41 | unsigned int b : 1; |
42 | unsigned int c : 1; |
43 | unsigned int d : 1; |
44 | unsigned int e : 1; |
45 | unsigned int f : 1; |
46 | unsigned int g : 1; |
47 | unsigned int h : 1; |
48 | unsigned int i : 1; |
49 | unsigned int j : 1; |
50 | unsigned int k : 1; |
51 | unsigned int l : 1; |
52 | unsigned int m : 1; |
53 | unsigned int n : 1; |
54 | X4(); |
55 | }; |
56 | |
57 | // CHECK: Type: struct X5 |
58 | struct PACKED X5 { |
59 | union { |
60 | long a; |
61 | long b; |
62 | }; |
63 | short l; |
64 | short r; |
65 | }; |
66 | |
67 | // CHECK: Type: struct X6 |
68 | struct __attribute__((aligned(16))) X6 { |
69 | int x; |
70 | int y; |
71 | virtual ~X6(); |
72 | }; |
73 | |
74 | // CHECK: Type: struct X7 |
75 | struct X7 { |
76 | int z; |
77 | }; |
78 | |
79 | // CHECK: Type: struct X8 |
80 | struct X8 : X6, virtual X7 { |
81 | char c; |
82 | }; |
83 | |
84 | void use_structs() { |
85 | X0 x0s[sizeof(X0)]; |
86 | X1 x1s[sizeof(X1)]; |
87 | X2 x2s[sizeof(X2)]; |
88 | X3 x3s[sizeof(X3)]; |
89 | X4 x4s[sizeof(X4)]; |
90 | X5 x5s[sizeof(X5)]; |
91 | X6 x6s[sizeof(X6)]; |
92 | X7 x7s[sizeof(X7)]; |
93 | X8 x8s[sizeof(X8)]; |
94 | x4s[1].a = 1; |
95 | x5s[1].a = 17; |
96 | } |
97 | |