blob: 57de8b525dcfad96bada7e335cf68436b8b59e0c [file] [log] [blame]
Argyrios Kyrtzidisc2501922013-07-12 22:30:03 +00001// RUN: %clang_cc1 -w -fdump-record-layouts %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
Douglas Gregor453dbcb2012-01-26 07:55:45 +00004// 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
Serge Pavlov0dcea352013-06-17 17:18:51 +000022void use_X0() { struct X0 x0; x0.x[5] = sizeof(struct X0); };
23
Douglas Gregor453dbcb2012-01-26 07:55:45 +000024// CHECK: Type: struct X1
25struct X1 {
26 char x[13];
27 struct X0 y;
28} PACKED;
29
Serge Pavlov0dcea352013-06-17 17:18:51 +000030void use_X1() { struct X1 x1; x1.x[5] = sizeof(struct X1); };
31
Douglas Gregor453dbcb2012-01-26 07:55:45 +000032// CHECK: Type: struct X2
33struct PACKED X2 {
34 short x;
35 int y;
36};
37
Serge Pavlov0dcea352013-06-17 17:18:51 +000038void use_X2() { struct X2 x2; x2.y = sizeof(struct X2); };
39
Douglas Gregor453dbcb2012-01-26 07:55:45 +000040// CHECK: Type: struct X3
41struct X3 {
42 short x PACKED;
43 int y;
44};
45
Serge Pavlov0dcea352013-06-17 17:18:51 +000046void use_X3() { struct X3 x3; x3.y = sizeof(struct X3); };
47
Douglas Gregor453dbcb2012-01-26 07:55:45 +000048#pragma pack(push,2)
49// CHECK: Type: struct X4
50struct X4 {
51 int x;
52 int y;
53};
54#pragma pack(pop)
55
Serge Pavlov0dcea352013-06-17 17:18:51 +000056void use_X4() { struct X4 x4; x4.y = sizeof(struct X4); };
57
Douglas Gregor453dbcb2012-01-26 07:55:45 +000058// CHECK: Type: struct X5
59struct PACKED X5 { double a[19]; signed char b; };
60
Serge Pavlov0dcea352013-06-17 17:18:51 +000061void use_X5() { struct X5 x5; x5.b = sizeof(struct X5); };
62
Douglas Gregor453dbcb2012-01-26 07:55:45 +000063// CHECK: Type: struct X6
64struct PACKED X6 { long double a; char b; };
65
Serge Pavlov0dcea352013-06-17 17:18:51 +000066void use_X6() { struct X6 x6; x6.b = sizeof(struct X6); };
67
Douglas Gregor453dbcb2012-01-26 07:55:45 +000068// CHECK: Type: struct X7
Douglas Gregora2a50282012-01-26 17:23:00 +000069struct X7 {
Douglas Gregor453dbcb2012-01-26 07:55:45 +000070 unsigned x;
71 unsigned char y;
72} PACKED;
73
Serge Pavlov0dcea352013-06-17 17:18:51 +000074void use_X7() { struct X7 x7; x7.y = x7.x = sizeof(struct X7); }
75
Douglas Gregor453dbcb2012-01-26 07:55:45 +000076// CHECK: Type: union X8
77union X8 {
78 struct X7 x;
79 unsigned y;
80} PACKED;
81
82// CHECK: Type: struct X9
83struct X9 {
84 unsigned int x[2] PACKED;
85 unsigned int y;
86 unsigned int z PACKED;
87};
88
89// CHECK: Type: struct X10
90struct X10 {
91 unsigned int x[2] PACKED;
92 unsigned int y PACKED;
93 unsigned int z PACKED;
94};
95
96// CHECK: Type: struct X11
97struct PACKED X11 {
98 unsigned int x[2];
99 unsigned int y;
100 unsigned int z;
101};
102
103// CHECK: Type: struct X12
104struct PACKED X12 {
105 int x : 24;
106};
107
108// CHECK: Type: struct X13
109struct PACKED X13 {
110 signed x : 10;
111 signed y : 10;
112};
113
114// CHECK: Type: union X14
115union PACKED X14 {
116 unsigned long long x : 3;
117};
118
119// CHECK: Type: struct X15
120struct X15 {
121 unsigned x : 16;
122 unsigned y : 28 PACKED;
123};
124
125// CHECK: Type: struct X16
126struct ALIGNED16 X16 {
127 int a, b, c;
128 int x : 5;
129 int y : 29;
130};
131
132void use_structs() {
Douglas Gregor453dbcb2012-01-26 07:55:45 +0000133 union X8 x8;
Douglas Gregora2a50282012-01-26 17:23:00 +0000134 typedef int X8array[sizeof(union X8)];
Douglas Gregor453dbcb2012-01-26 07:55:45 +0000135 x8.y = sizeof(union X8);
Douglas Gregora2a50282012-01-26 17:23:00 +0000136 x8.x.x = x8.y;
Douglas Gregor453dbcb2012-01-26 07:55:45 +0000137
138 struct X9 x9;
Douglas Gregora2a50282012-01-26 17:23:00 +0000139 typedef int X9array[sizeof(struct X9)];
Douglas Gregor453dbcb2012-01-26 07:55:45 +0000140 x9.y = sizeof(struct X9);
141
142 struct X10 x10;
Douglas Gregora2a50282012-01-26 17:23:00 +0000143 typedef int X10array[sizeof(struct X10)];
Douglas Gregor453dbcb2012-01-26 07:55:45 +0000144 x10.y = sizeof(struct X10);
145
146 struct X11 x11;
Douglas Gregora2a50282012-01-26 17:23:00 +0000147 typedef int X11array[sizeof(struct X11)];
Douglas Gregor453dbcb2012-01-26 07:55:45 +0000148 x11.y = sizeof(struct X11);
149
150 struct X12 x12;
151 x12.x = sizeof(struct X12);
152
153 struct X13 x13;
154 x13.x = sizeof(struct X13);
155
156 union X14 x14;
157 x14.x = sizeof(union X14);
158
159 struct X15 x15;
160 x15.x = sizeof(struct X15);
161
162 struct X16 x16;
163 x16.x = sizeof(struct X16);
164}