blob: 44b58f07781f8e404d50ded3b2dfcc2abeded63d [file] [log] [blame]
Douglas Gregor453dbcb2012-01-26 07:55:45 +00001// RUN: %clang_cc1 -fdump-record-layouts %s 2> %t.layouts
2// RUN: %clang_cc1 -fdump-record-layouts-simple %s > %t.before 2>&1
3// RUN: %clang_cc1 -DPACKED= -DALIGNED16= -fdump-record-layouts-simple -foverride-record-layout=%t.layouts %s > %t.after 2>&1
4// RUN: diff %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// If not explicitly disabled, set ALIGNED16 to 16-byte alignment.
13#ifndef ALIGNED16
14# define ALIGNED16 __attribute__((aligned(16)))
15#endif
16
17// CHECK: Type: struct X0
18struct X0 {
19 int x[6] PACKED;
20};
21
22// CHECK: Type: struct X1
23struct X1 {
24 char x[13];
25 struct X0 y;
26} PACKED;
27
28// CHECK: Type: struct X2
29struct PACKED X2 {
30 short x;
31 int y;
32};
33
34// CHECK: Type: struct X3
35struct X3 {
36 short x PACKED;
37 int y;
38};
39
40#pragma pack(push,2)
41// CHECK: Type: struct X4
42struct X4 {
43 int x;
44 int y;
45};
46#pragma pack(pop)
47
48// CHECK: Type: struct X5
49struct PACKED X5 { double a[19]; signed char b; };
50
51// CHECK: Type: struct X6
52struct PACKED X6 { long double a; char b; };
53
54// CHECK: Type: struct X7
55typedef struct X7 {
56 unsigned x;
57 unsigned char y;
58} PACKED;
59
60// CHECK: Type: union X8
61union X8 {
62 struct X7 x;
63 unsigned y;
64} PACKED;
65
66// CHECK: Type: struct X9
67struct X9 {
68 unsigned int x[2] PACKED;
69 unsigned int y;
70 unsigned int z PACKED;
71};
72
73// CHECK: Type: struct X10
74struct X10 {
75 unsigned int x[2] PACKED;
76 unsigned int y PACKED;
77 unsigned int z PACKED;
78};
79
80// CHECK: Type: struct X11
81struct PACKED X11 {
82 unsigned int x[2];
83 unsigned int y;
84 unsigned int z;
85};
86
87// CHECK: Type: struct X12
88struct PACKED X12 {
89 int x : 24;
90};
91
92// CHECK: Type: struct X13
93struct PACKED X13 {
94 signed x : 10;
95 signed y : 10;
96};
97
98// CHECK: Type: union X14
99union PACKED X14 {
100 unsigned long long x : 3;
101};
102
103// CHECK: Type: struct X15
104struct X15 {
105 unsigned x : 16;
106 unsigned y : 28 PACKED;
107};
108
109// CHECK: Type: struct X16
110struct ALIGNED16 X16 {
111 int a, b, c;
112 int x : 5;
113 int y : 29;
114};
115
116void use_structs() {
117 struct X0 x0;
118 x0.x[5] = sizeof(struct X0);
119
120 struct X1 x1;
121 x1.x[5] = sizeof(struct X1);
122
123 struct X2 x2;
124 x2.y = sizeof(struct X2);
125
126 struct X3 x3;
127 x3.y = sizeof(struct X3);
128
129 struct X4 x4;
130 x4.y = sizeof(struct X4);
131
132 struct X5 x5;
133 x5.b = sizeof(struct X5);
134
135 struct X6 x6;
136 x6.b = sizeof(struct X6);
137
138 struct X7 x7;
139 x7.x = sizeof(struct X7);
140
141 union X8 x8;
142 x8.y = sizeof(union X8);
143
144 struct X9 x9;
145 x9.y = sizeof(struct X9);
146
147 struct X10 x10;
148 x10.y = sizeof(struct X10);
149
150 struct X11 x11;
151 x11.y = sizeof(struct X11);
152
153 struct X12 x12;
154 x12.x = sizeof(struct X12);
155
156 struct X13 x13;
157 x13.x = sizeof(struct X13);
158
159 union X14 x14;
160 x14.x = sizeof(union X14);
161
162 struct X15 x15;
163 x15.x = sizeof(struct X15);
164
165 struct X16 x16;
166 x16.x = sizeof(struct X16);
167}