[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / Layout / aix-bitfield-alignment.c
blobd47b3d7a0c7d89b8914cedae50d8f6d2134bfce3
1 // RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -fdump-record-layouts \
2 // RUN: -fsyntax-only -fxl-pragma-pack -x c %s | \
3 // RUN: FileCheck --check-prefixes=CHECK,CHECK32 %s
4 // RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -fdump-record-layouts \
5 // RUN: -fsyntax-only -fxl-pragma-pack -x c++ %s | \
6 // RUN: FileCheck --check-prefixes=CHECK,CHECK32 %s
8 // RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -fdump-record-layouts \
9 // RUN: -fsyntax-only -fxl-pragma-pack -x c %s | \
10 // RUN: FileCheck --check-prefixes=CHECK,CHECK64 %s
11 // RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -fdump-record-layouts \
12 // RUN: -fsyntax-only -fxl-pragma-pack -x c++ %s | \
13 // RUN: FileCheck --check-prefixes=CHECK,CHECK64 %s
15 struct A {
16 unsigned char c : 2;
17 } A;
19 int a = sizeof(A);
21 // CHECK: *** Dumping AST Record Layout
22 // CHECK-NEXT: 0 | struct A
23 // CHECK-NEXT: 0:0-1 | unsigned char c
24 // CHECK-NEXT: sizeof=4, {{(dsize=4, )?}}align=4, preferredalign=4
26 struct B {
27 char c;
28 int : 0;
29 } B;
31 int b = sizeof(B);
33 // CHECK: *** Dumping AST Record Layout
34 // CHECK-NEXT: 0 | struct B
35 // CHECK-NEXT: 0 | char c
36 // CHECK-NEXT: 4:- | int
37 // CHECK-NEXT: sizeof=4, {{(dsize=4, )?}}align=4, preferredalign=4
39 struct C {
40 signed int a1 : 6;
41 signed char a2 : 4;
42 short int a3 : 2;
43 int a4 : 2;
44 signed long a5 : 5;
45 long long int a6 : 6;
46 unsigned long a7 : 8;
47 } C;
49 int c = sizeof(C);
51 // CHECK: *** Dumping AST Record Layout
52 // CHECK-NEXT: 0 | struct C
53 // CHECK-NEXT: 0:0-5 | int a1
54 // CHECK-NEXT: 0:6-9 | signed char a2
55 // CHECK-NEXT: 1:2-3 | short a3
56 // CHECK-NEXT: 1:4-5 | int a4
57 // CHECK-NEXT: 1:6-10 | long a5
58 // CHECK-NEXT: 2:3-8 | long long a6
59 // CHECK32: 4:0-7 | unsigned long a7
60 // CHECK32: sizeof=8, {{(dsize=8, )?}}align=4, preferredalign=4
61 // CHECK64: 3:1-8 | unsigned long a7
62 // CHECK64: sizeof=8, {{(dsize=8, )?}}align=8, preferredalign=8
64 #pragma align(packed)
65 struct C1 {
66 signed int a1 : 6;
67 signed char a2 : 4;
68 short int a3 : 2;
69 int a4 : 2;
70 signed long a5 : 5;
71 long long int a6 : 6;
72 unsigned long a7 : 8;
73 } C1;
74 #pragma align(reset)
76 int c1 = sizeof(C1);
78 // CHECK: *** Dumping AST Record Layout
79 // CHECK-NEXT: 0 | struct C1
80 // CHECK-NEXT: 0:0-5 | int a1
81 // CHECK-NEXT: 0:6-9 | signed char a2
82 // CHECK-NEXT: 1:2-3 | short a3
83 // CHECK-NEXT: 1:4-5 | int a4
84 // CHECK-NEXT: 1:6-10 | long a5
85 // CHECK-NEXT: 2:3-8 | long long a6
86 // CHECK-NEXT: 3:1-8 | unsigned long a7
87 // CHECK-NEXT: sizeof=5, {{(dsize=5, )?}}align=1, preferredalign=1
89 #pragma pack(4)
90 struct C2 {
91 signed int a1 : 6;
92 signed char a2 : 4;
93 short int a3 : 2;
94 int a4 : 2;
95 signed long a5 : 5;
96 long long int a6 : 6;
97 unsigned long a7 : 8;
98 } C2;
99 #pragma pack(pop)
101 int c2 = sizeof(C2);
103 // CHECK: *** Dumping AST Record Layout
104 // CHECK-NEXT: 0 | struct C2
105 // CHECK-NEXT: 0:0-5 | int a1
106 // CHECK-NEXT: 0:6-9 | signed char a2
107 // CHECK-NEXT: 1:2-3 | short a3
108 // CHECK-NEXT: 1:4-5 | int a4
109 // CHECK-NEXT: 1:6-10 | long a5
110 // CHECK-NEXT: 2:3-8 | long long a6
111 // CHECK-NEXT: 3:1-8 | unsigned long a7
112 // CHECK-NEXT: sizeof=8, {{(dsize=8, )?}}align=4, preferredalign=4
114 typedef __attribute__((aligned(32))) short mySHORT;
115 struct D {
116 char c : 8;
117 mySHORT : 0;
118 } D;
120 int d = sizeof(D);
122 // CHECK: *** Dumping AST Record Layout
123 // CHECK-NEXT: 0 | struct D
124 // CHECK-NEXT: 0:0-7 | char c
125 // CHECK-NEXT: 32:- | mySHORT
126 // CHECK-NEXT: sizeof=32, {{(dsize=32, )?}}align=32, preferredalign=32
128 typedef __attribute__((aligned(32))) long myLONG;
129 struct D11 {
130 char c : 8;
131 myLONG : 0;
132 } D11;
134 int d11 = sizeof(D11);
136 // CHECK: *** Dumping AST Record Layout
137 // CHECK-NEXT: 0 | struct D11
138 // CHECK-NEXT: 0:0-7 | char c
139 // CHECK-NEXT: 32:- | myLONG
140 // CHECK-NEXT: sizeof=32, {{(dsize=32, )?}}align=32, preferredalign=32
142 typedef __attribute__((aligned(2))) long myLONG2;
143 struct D12 {
144 char c : 8;
145 myLONG2 : 0;
146 } D12;
148 int d12 = sizeof(D12);
150 // CHECK: *** Dumping AST Record Layout
151 // CHECK-NEXT: 0 | struct D12
152 // CHECK-NEXT: 0:0-7 | char c
153 // CHECK32: 4:- | myLONG2
154 // CHECK32: sizeof=4, {{(dsize=4, )?}}align=4, preferredalign=4
155 // CHECK64: 8:- | myLONG2
156 // CHECK64: sizeof=8, {{(dsize=8, )?}}align=8, preferredalign=8
158 typedef __attribute__((aligned(32))) long long myLONGLONG;
159 struct D21 {
160 char c : 8;
161 myLONGLONG : 0;
162 } D21;
164 int d21 = sizeof(D21);
166 // CHECK: *** Dumping AST Record Layout
167 // CHECK-NEXT: 0 | struct D21
168 // CHECK-NEXT: 0:0-7 | char c
169 // CHECK-NEXT: 32:- | myLONGLONG
170 // CHECK-NEXT: sizeof=32, {{(dsize=32, )?}}align=32, preferredalign=32
172 typedef __attribute__((aligned(2))) long long myLONGLONG2;
173 struct D22 {
174 char c : 8;
175 myLONGLONG2 : 0;
176 } D22;
178 int d22 = sizeof(D22);
180 // CHECK: *** Dumping AST Record Layout
181 // CHECK-NEXT: 0 | struct D22
182 // CHECK-NEXT: 0:0-7 | char c
183 // CHECK32: 4:- | myLONGLONG2
184 // CHECK32: sizeof=4, {{(dsize=4, )?}}align=4, preferredalign=4
185 // CHECK64: 8:- | myLONGLONG2
186 // CHECK64: sizeof=8, {{(dsize=8, )?}}align=8, preferredalign=8
188 enum LL : unsigned long long { val = 1 };
190 struct E {
191 enum LL e : 32;
192 } E;
194 int e = sizeof(E);
196 // CHECK: *** Dumping AST Record Layout
197 // CHECK-NEXT: 0 | struct E
198 // CHECK-NEXT: 0:0-31 | enum LL e
199 // CHECK32-NEXT: sizeof=4, {{(dsize=4, )?}}align=4, preferredalign=4
200 // CHECK64-NEXT: sizeof=8, {{(dsize=8, )?}}align=8, preferredalign=8
202 enum LL1 : unsigned long long { val1 = 1 } __attribute__((aligned(16)));
203 struct E1 {
204 enum LL1 e : 32;
205 } E1;
207 int e1 = sizeof(E1);
209 // CHECK: *** Dumping AST Record Layout
210 // CHECK-NEXT: 0 | struct E1
211 // CHECK-NEXT: 0:0-31 | enum LL1 e
212 // CHECK-NEXT: sizeof=16, {{(dsize=16, )?}}align=16, preferredalign=16
214 struct F {
215 long long l : 32 __attribute__((aligned(16)));
216 } F;
218 int f = sizeof(F);
220 // CHECK: *** Dumping AST Record Layout
221 // CHECK-NEXT: 0 | struct F
222 // CHECK-NEXT: 0:0-31 | long long l
223 // CHECK-NEXT: sizeof=16, {{(dsize=16, )?}}align=16, preferredalign=16
225 struct G {
226 long long ll : 45;
227 } G;
229 int s = sizeof(G);
231 // CHECK: *** Dumping AST Record Layout
232 // CHECK-NEXT: 0 | struct G
233 // CHECK-NEXT: 0:0-44 | long long ll
234 // CHECK-NEXT: sizeof=8, {{(dsize=8, )?}}align=8, preferredalign=8
236 #pragma align(packed)
237 struct H {
238 char c;
239 int : 0;
240 int i;
241 } H;
242 #pragma align(reset)
244 int h = sizeof(H);
246 // CHECK: *** Dumping AST Record Layout
247 // CHECK-NEXT: 0 | struct H
248 // CHECK-NEXT: 0 | char c
249 // CHECK-NEXT: 4:- | int
250 // CHECK-NEXT: 4 | int i
251 // CHECK-NEXT: sizeof=8, {{(dsize=8, )?}}align=1, preferredalign=1
253 #pragma pack(2)
254 struct I {
255 char c;
256 int : 0;
257 int i;
258 } I;
259 #pragma pack(pop)
261 int i = sizeof(I);
263 // CHECK: *** Dumping AST Record Layout
264 // CHECK-NEXT: 0 | struct I
265 // CHECK-NEXT: 0 | char c
266 // CHECK-NEXT: 4:- | int
267 // CHECK-NEXT: 4 | int i
268 // CHECK-NEXT: sizeof=8, {{(dsize=8, )?}}align=2, preferredalign=2