[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Sema / aix-pragma-pack-and-align.c
bloba01eb14f68eada9afd784661b33c89cb5412dff2
1 // RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -fdump-record-layouts \
2 // RUN: -fxl-pragma-pack -verify -fsyntax-only -x c++ %s | \
3 // RUN: FileCheck %s
5 // RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -fdump-record-layouts \
6 // RUN: -fxl-pragma-pack -verify -fsyntax-only -x c++ %s | \
7 // RUN: FileCheck %s
9 namespace test1 {
10 #pragma align(natural)
11 #pragma pack(4)
12 #pragma pack(2)
13 struct A {
14 int i;
15 double d;
18 int a = sizeof(A);
19 #pragma pack()
20 #pragma pack(show) // expected-warning {{value of #pragma pack(show) == 4}}
21 #pragma pack(pop)
22 #pragma pack(show) // expected-warning {{value of #pragma pack(show) == 8}}
23 struct B {
24 int i;
25 double d;
27 #pragma align(reset)
29 int b = sizeof(B);
31 // CHECK: *** Dumping AST Record Layout
32 // CHECK-NEXT: 0 | struct test1::A
33 // CHECK-NEXT: 0 | int i
34 // CHECK-NEXT: 4 | double d
35 // CHECK-NEXT: | [sizeof=12, dsize=12, align=2, preferredalign=2,
36 // CHECK-NEXT: | nvsize=12, nvalign=2, preferrednvalign=2]
38 // CHECK: *** Dumping AST Record Layout
39 // CHECK-NEXT: 0 | struct test1::B
40 // CHECK-NEXT: 0 | int i
41 // CHECK-NEXT: 8 | double d
42 // CHECK-NEXT: | [sizeof=16, dsize=16, align=4, preferredalign=8,
43 // CHECK-NEXT: | nvsize=16, nvalign=4, preferrednvalign=8]
45 } // namespace test1
47 namespace test2 {
48 #pragma align(natural)
49 #pragma pack(2)
50 struct A {
51 int i;
52 double d;
55 int a = sizeof(A);
56 #pragma align(reset)
58 struct B {
59 int i;
60 double d;
63 int b = sizeof(B);
65 // CHECK: *** Dumping AST Record Layout
66 // CHECK-NEXT: 0 | struct test2::A
67 // CHECK-NEXT: 0 | int i
68 // CHECK-NEXT: 4 | double d
69 // CHECK-NEXT: | [sizeof=12, dsize=12, align=2, preferredalign=2,
70 // CHECK-NEXT: | nvsize=12, nvalign=2, preferrednvalign=2]
72 // CHECK: *** Dumping AST Record Layout
73 // CHECK-NEXT: 0 | struct test2::B
74 // CHECK-NEXT: 0 | int i
75 // CHECK-NEXT: 4 | double d
76 // CHECK-NEXT: | [sizeof=12, dsize=12, align=4, preferredalign=4,
77 // CHECK-NEXT: | nvsize=12, nvalign=4, preferrednvalign=4]
79 } // namespace test2
81 namespace test3 {
82 #pragma pack(2)
83 #pragma align(natural)
84 struct A {
85 double d;
87 #pragma align(reset)
88 #pragma pack(pop)
90 int a = sizeof(A);
92 // CHECK: *** Dumping AST Record Layout
93 // CHECK-NEXT: 0 | struct test3::A
94 // CHECK-NEXT: 0 | double d
95 // CHECK-NEXT: | [sizeof=8, dsize=8, align=4, preferredalign=8,
96 // CHECK-NEXT: | nvsize=8, nvalign=4, preferrednvalign=8]
98 } // namespace test3
100 namespace test4 {
101 #pragma pack(2)
102 #pragma align(natural)
103 #pragma pack(pop)
105 struct A {
106 int i;
107 double d;
108 } a;
109 #pragma align(reset)
110 #pragma pack(pop)
112 int i = sizeof(A);
114 // CHECK: *** Dumping AST Record Layout
115 // CHECK-NEXT: 0 | struct test4::A
116 // CHECK-NEXT: 0 | int i
117 // CHECK-NEXT: 8 | double d
118 // CHECK-NEXT: | [sizeof=16, dsize=16, align=4, preferredalign=8,
119 // CHECK-NEXT: | nvsize=16, nvalign=4, preferrednvalign=8]
121 } // namespace test4
123 namespace test5 {
124 #pragma align(power)
125 #pragma align(natural)
126 #pragma pack(2)
127 #pragma align(reset)
128 struct A {
129 int i;
130 double d;
132 #pragma align(reset)
134 int a = sizeof(A);
136 // CHECK: *** Dumping AST Record Layout
137 // CHECK-NEXT: 0 | struct test5::A
138 // CHECK-NEXT: 0 | int i
139 // CHECK-NEXT: 4 | double d
140 // CHECK-NEXT: | [sizeof=12, dsize=12, align=4, preferredalign=4,
141 // CHECK-NEXT: | nvsize=12, nvalign=4, preferrednvalign=4]
143 } // namespace test5
145 namespace test6 {
146 #pragma align(natural)
147 #pragma pack(0) // expected-error {{expected #pragma pack parameter to be '1', '2', '4', '8', or '16'}}
148 #pragma pack(show) // expected-warning {{value of #pragma pack(show) == 8}}
150 struct A {
151 int i;
152 double d;
153 } a;
154 #pragma align(reset)
156 int i = sizeof(a);
158 // CHECK: *** Dumping AST Record Layout
159 // CHECK-NEXT: 0 | struct test6::A
160 // CHECK-NEXT: 0 | int i
161 // CHECK-NEXT: 8 | double d
162 // CHECK-NEXT: | [sizeof=16, dsize=16, align=4, preferredalign=8,
163 // CHECK-NEXT: | nvsize=16, nvalign=4, preferrednvalign=8]
165 } // namespace test6
167 namespace test7 {
168 #pragma align = natural // expected-warning {{missing '(' after '#pragma align' - ignoring}}
169 #pragma align(reset) // expected-warning {{#pragma options align=reset failed: stack empty}}
170 } // namespace test7
172 namespace test8 {
173 #pragma align(packed)
174 #pragma pack(2)
175 #pragma pack(show) // expected-warning {{value of #pragma pack(show) == 2}}
176 struct A {
177 int i;
178 double d;
180 #pragma align(reset)
182 int a = sizeof(A);
184 // CHECK: *** Dumping AST Record Layout
185 // CHECK-NEXT: 0 | struct test8::A
186 // CHECK-NEXT: 0 | int i
187 // CHECK-NEXT: 4 | double d
188 // CHECK-NEXT: | [sizeof=12, dsize=12, align=2, preferredalign=2,
189 // CHECK-NEXT: | nvsize=12, nvalign=2, preferrednvalign=2]
191 } // namespace test8
193 namespace test9 {
194 #pragma pack(push, r1, 2) // expected-error {{specifying an identifier within `#pragma pack` is not supported on this target}}
195 struct A {
196 int i;
197 double d;
199 #pragma pack(pop) // expected-warning {{#pragma pack(pop, ...) failed: stack empty}}
201 int a = sizeof(A);
203 // CHECK: *** Dumping AST Record Layout
204 // CHECK-NEXT: 0 | struct test9::A
205 // CHECK-NEXT: 0 | int i
206 // CHECK-NEXT: 4 | double d
207 // CHECK-NEXT: | [sizeof=12, dsize=12, align=4, preferredalign=4,
208 // CHECK-NEXT: | nvsize=12, nvalign=4, preferrednvalign=4]
210 } // namespace test9
212 namespace test10 {
213 #pragma pack(2)
214 #pragma align(reset)
215 struct A {
216 int i;
217 double d;
220 int a = sizeof(A);
222 // CHECK: *** Dumping AST Record Layout
223 // CHECK-NEXT: 0 | struct test10::A
224 // CHECK-NEXT: 0 | int i
225 // CHECK-NEXT: 4 | double d
226 // CHECK-NEXT: | [sizeof=12, dsize=12, align=4, preferredalign=4,
227 // CHECK-NEXT: | nvsize=12, nvalign=4, preferrednvalign=4]
229 } // namespace test10