[VPlan] Move initial VPlan block creation to constructor. (NFC)
[llvm-project.git] / clang / test / ASTMerge / APValue / APValue.cpp
blobc8695fb6074bb70aa3a2b92c3910d16700994cf6
1 // RUN: %clang_cc1 -std=gnu++2a -emit-pch %s -o %t.pch
2 // RUN: %clang_cc1 -std=gnu++2a %s -DEMIT -ast-merge %t.pch -ast-dump-all | FileCheck %s
4 // XFAIL: *
6 #ifndef EMIT
7 #define EMIT
9 namespace Integer {
11 consteval int fint() {
12 return 6789;
15 int Unique_Int = fint();
16 //CHECK: VarDecl {{.*}} Unique_Int
17 //CHECK-NEXT: ConstantExpr {{.*}} 'int'
18 //CHECK-NEXT: value: Int 6789
20 consteval __uint128_t fint128() {
21 return ((__uint128_t)0x75f17d6b3588f843 << 64) | 0xb13dea7c9c324e51;
24 constexpr __uint128_t Unique_Int128 = fint128();
25 //CHECK: VarDecl {{.*}} Unique_Int128
26 //CHECK-NEXT: value: Int 156773562844924187900898496343692168785
27 //CHECK-NEXT: ConstantExpr
28 //CHECK-NEXT: value: Int 156773562844924187900898496343692168785
30 } // namespace Integer
32 namespace FloatingPoint {
34 consteval double fdouble() {
35 return double(567890.67890);
38 double Unique_Double = fdouble();
39 //CHECK: VarDecl {{.*}} Unique_Double
40 //CHECK-NEXT: ConstantExpr {{.*}}
41 //CHECK-NEXT: value: Float 5.678907e+05
43 } // namespace FloatingPoint
45 // FIXME: Add test for FixedPoint, ComplexInt, ComplexFloat, AddrLabelDiff.
47 namespace Struct {
49 struct B {
50 int i;
51 double d;
54 consteval B fB() {
55 return B{1, 0.7};
58 constexpr B Basic_Struct = fB();
59 //CHECK: VarDecl {{.*}} Basic_Struct
60 //CHECK-NEXT: value: Struct
61 //CHECK-NEXT: fields: Int 1, Float 7.000000e-01
62 //CHECK-NEXT: ImplicitCastExpr
63 //CHECK-NEXT: ConstantExpr
64 //CHECK-NEXT: value: Struct
65 //CHECK-NEXT: fields: Int 1, Float 7.000000e-01
67 struct C {
68 int i = 9;
71 struct A : B {
72 constexpr A(B b, int I, double D, C _c) : B(b), i(I), d(D), c(_c) {}
73 int i;
74 double d;
75 C c;
78 consteval A fA() {
79 return A(Basic_Struct, 1, 79.789, {});
82 A Advanced_Struct = fA();
83 //CHECK: VarDecl {{.*}} Advanced_Struct
84 //CHECK-NEXT: ConstantExpr {{.*}}
85 //CHECK-NEXT: value: Struct
86 //CHECK-NEXT: base: Struct
87 //CHECK-NEXT: fields: Int 1, Float 7.000000e-01
88 //CHECK-NEXT: fields: Int 1, Float 7.978900e+01
89 //CHECK-NEXT: field: Struct
90 //CHECK-NEXT: field: Int 9
92 } // namespace Struct
94 namespace Vector {
96 using v4si = int __attribute__((__vector_size__(16)));
98 consteval v4si fv4si() {
99 return (v4si){8, 2, 3};
102 v4si Vector_Int = fv4si();
103 //CHECK: VarDecl {{.*}} Vector_Int
104 //CHECK-NEXT: ConstantExpr
105 //CHECK-NEXT: value: Vector length=4
106 //CHECK-NEXT: elements: Int 8, Int 2, Int 3, Int 0
108 } // namespace Vector
110 namespace Array {
112 struct B {
113 int arr[6];
116 consteval B fint() {
117 return B{1, 2, 3, 4, 5, 6};
120 B Array_Int = fint();
121 //CHECK: VarDecl {{.*}} Array_Int
122 //CHECK-NEXT: ConstantExpr
123 //CHECK-NEXT: value: Struct
124 //CHECK-NEXT: field: Array size=6
125 //CHECK-NEXT: elements: Int 1, Int 2, Int 3, Int 4
126 //CHECK-NEXT: elements: Int 5, Int 6
128 struct A {
129 int i = 789;
130 double d = 67890.09876;
133 struct C {
134 A arr[3];
137 consteval C fA() {
138 return {{A{}, A{-45678, 9.8}, A{9}}};
141 C Array2_Struct = fA();
142 //CHECK: VarDecl {{.*}} Array2_Struct
143 //CHECK-NEXT: ConstantExpr {{.*}}
145 using v4si = int __attribute__((__vector_size__(16)));
147 struct D {
148 v4si arr[2];
151 consteval D fv4si() {
152 return {{{1, 2, 3, 4}, {4, 5, 6, 7}}};
155 D Array_Vector = fv4si();
156 //CHECK: VarDecl {{.*}} Array_Vector
157 //CHECK-NEXT: ConstantExpr {{.*}}
158 //CHECK-NEXT: value: Struct
159 //CHECK-NEXT: field: Array size=2
160 //CHECK-NEXT: element: Vector length=4
161 //CHECK-NEXT: elements: Int 1, Int 2, Int 3, Int 4
162 //CHECK-NEXT: element: Vector length=4
163 //CHECK-NEXT: elements: Int 4, Int 5, Int 6, Int 7
165 } // namespace Array
167 namespace Union {
169 struct A {
170 int i = 6789;
171 float f = 987.9876;
174 union U {
175 int i;
176 A a{567890, 9876.5678f};
179 consteval U fU1() {
180 return U{0};
183 U Unique_Union1 = fU1();
184 //CHECK: VarDecl {{.*}} Unique_Union
185 //CHECK-NEXT: ConstantExpr
186 //CHECK-NEXT: value: Union .i Int 0
188 consteval U fU() {
189 return U{};
192 U Unique_Union2 = fU();
193 //CHECK: VarDecl {{.*}} Unique_Union
194 //CHECK-NEXT: ConstantExpr
195 //CHECK-NEXT: value: Union .a
196 //CHECK-NEXT: Struct
197 //CHECK-NEXT: fields: Int 567890, Float 9.876567e+03
199 } // namespace Union
201 namespace MemberPointer {
203 struct A {
204 struct B {
205 struct C {
206 struct D {
207 struct E {
208 struct F {
209 struct G {
210 int i;
219 consteval auto fmem_ptr() -> decltype(&A::B::C::D::E::F::G::i) {
220 return &A::B::C::D::E::F::G::i;
223 auto MemberPointer1 = fmem_ptr();
224 //CHECK: VarDecl {{.*}} MemberPointer1
225 //CHECK-NEXT: ConstantExpr
226 //CHECK-NEXT: value: MemberPointer &G::i
228 struct A1 {
229 struct B1 {
230 int f() const {
231 return 0;
236 consteval auto fmem_ptr2() {
237 return &A1::B1::f;
240 auto MemberPointer2 = fmem_ptr2();
241 //CHECK: VarDecl {{.*}} MemberPointer2
242 //CHECK-NEXT: ConstantExpr
243 //CHECK-NEXT: value: MemberPointer &B1::f
245 } // namespace MemberPointer
247 namespace std {
248 struct type_info;
251 namespace LValue {
253 constexpr int g = 0;
255 consteval const int &fg_ref() {
256 return g;
259 const int &g_ref = fg_ref();
260 //CHECK: VarDecl {{.*}} g_ref
261 //CHECK-NEXT: ConstantExpr
262 //CHECK-NEXT: value: LValue &g
264 consteval const int *fint_ptr() {
265 return &g;
268 const int *g_ptr = fint_ptr();
269 //CHECK: VarDecl {{.*}} g_ptr
270 //CHECK-NEXT: ConstantExpr
271 //CHECK-NEXT: value: LValue &g
273 consteval const int *fnull_ptr() {
274 return nullptr;
277 const int *ptr2 = fnull_ptr();
278 //CHECK: VarDecl {{.*}} ptr2
279 //CHECK-NEXT: ConstantExpr
280 //CHECK-NEXT: value: LValue nullptr
282 int fconst();
284 consteval auto ffunc_ptr() {
285 return &fconst;
288 int (*func_ptr)() = ffunc_ptr();
289 //CHECK: VarDecl {{.*}} func_ptr
290 //CHECK-NEXT: ConstantExpr {{.*}}
291 //CHECK-NEXT: value: LValue &fconst
293 struct A {
294 int Arr[6] = {0, 1, 3, 4, 5, 9};
295 int i = 0;
298 struct D {
299 A arr[6] = {};
302 consteval D fA() {
303 return {};
306 constexpr D Arr = fA();
307 // CHECK: VarDecl {{.*}} Arr
308 // CHECK-NEXT: value: Struct
309 // CHECK-NEXT: field: Array size=6
310 // CHECK-NEXT: element: Struct
311 // CHECK-NEXT: field: Array size=6
312 // CHECK-NEXT: elements: Int 0, Int 1, Int 3, Int 4
313 // CHECK-NEXT: elements: Int 5, Int 9
314 // CHECK-NEXT: field: Int 0
315 // CHECK-NEXT: element: Struct
316 // CHECK-NEXT: field: Array size=6
317 // CHECK-NEXT: elements: Int 0, Int 1, Int 3, Int 4
318 // CHECK-NEXT: elements: Int 5, Int 9
319 // CHECK-NEXT: field: Int 0
320 // CHECK-NEXT: element: Struct
321 // CHECK-NEXT: field: Array size=6
322 // CHECK-NEXT: elements: Int 0, Int 1, Int 3, Int 4
323 // CHECK-NEXT: elements: Int 5, Int 9
324 // CHECK-NEXT: field: Int 0
325 // CHECK-NEXT: element: Struct
326 // CHECK-NEXT: field: Array size=6
327 // CHECK-NEXT: elements: Int 0, Int 1, Int 3, Int 4
328 // CHECK-NEXT: elements: Int 5, Int 9
329 // CHECK-NEXT: field: Int 0
330 // CHECK-NEXT: element: Struct
331 // CHECK-NEXT: field: Array size=6
332 // CHECK-NEXT: elements: Int 0, Int 1, Int 3, Int 4
333 // CHECK-NEXT: elements: Int 5, Int 9
334 // CHECK-NEXT: field: Int 0
335 // CHECK-NEXT: element: Struct
336 // CHECK-NEXT: field: Array size=6
337 // CHECK-NEXT: elements: Int 0, Int 1, Int 3, Int 4
338 // CHECK-NEXT: elements: Int 5, Int 9
339 // CHECK-NEXT: field: Int 0
340 // CHECK-NEXT: ImplicitCastExpr
341 // CHECK-NEXT: ConstantExpr
342 // CHECK-NEXT: value: Struct
343 // CHECK-NEXT: field: Array size=6
344 // CHECK-NEXT: element: Struct
345 // CHECK-NEXT: field: Array size=6
346 // CHECK-NEXT: elements: Int 0, Int 1, Int 3, Int 4
347 // CHECK-NEXT: elements: Int 5, Int 9
348 // CHECK-NEXT: field: Int 0
349 // CHECK-NEXT: element: Struct
350 // CHECK-NEXT: field: Array size=6
351 // CHECK-NEXT: elements: Int 0, Int 1, Int 3, Int 4
352 // CHECK-NEXT: elements: Int 5, Int 9
353 // CHECK-NEXT: field: Int 0
354 // CHECK-NEXT: element: Struct
355 // CHECK-NEXT: field: Array size=6
356 // CHECK-NEXT: elements: Int 0, Int 1, Int 3, Int 4
357 // CHECK-NEXT: elements: Int 5, Int 9
358 // CHECK-NEXT: field: Int 0
359 // CHECK-NEXT: element: Struct
360 // CHECK-NEXT: field: Array size=6
361 // CHECK-NEXT: elements: Int 0, Int 1, Int 3, Int 4
362 // CHECK-NEXT: elements: Int 5, Int 9
363 // CHECK-NEXT: field: Int 0
364 // CHECK-NEXT: element: Struct
365 // CHECK-NEXT: field: Array size=6
366 // CHECK-NEXT: elements: Int 0, Int 1, Int 3, Int 4
367 // CHECK-NEXT: elements: Int 5, Int 9
368 // CHECK-NEXT: field: Int 0
369 // CHECK-NEXT: element: Struct
370 // CHECK-NEXT: field: Array size=6
371 // CHECK-NEXT: elements: Int 0, Int 1, Int 3, Int 4
372 // CHECK-NEXT: elements: Int 5, Int 9
373 // CHECK-NEXT: field: Int 0
375 consteval const int &fconstintref() {
376 return Arr.arr[0].i;
379 const int &ArrayStructRef1 = fconstintref();
380 //CHECK: VarDecl {{.*}} ArrayStructRef1
381 //CHECK-NEXT: ConstantExpr
382 //CHECK-NEXT: value: LValue &Arr.arr[0].i
384 consteval const int &fconstintref2() {
385 return Arr.arr[1].Arr[5];
388 const int &ArrayStructRef2 = fconstintref2();
389 //CHECK: VarDecl {{.*}} ArrayStructRef2
390 //CHECK-NEXT: ConstantExpr
391 //CHECK-NEXT: value: LValue &Arr.arr[1].Arr[5]
393 consteval const int *fconststar() {
394 return &ArrayStructRef2;
397 const int *ArrayStructRef3 = fconststar();
398 //CHECK: VarDecl {{.*}} ArrayStructRef3
399 //CHECK-NEXT: ConstantExpr
400 //CHECK-NEXT: value: LValue &Arr.arr[1].Arr[5]
402 struct B : A {
405 struct C {
406 B b;
409 consteval C fC() {
410 return {};
413 C c = fC();
414 //CHECK: VarDecl {{.*}} c
415 //CHECK-NEXT: ConstantExpr
416 //CHECK-NEXT: value: Struct
417 //CHECK-NEXT: field: Struct
418 //CHECK-NEXT: base: Struct
419 //CHECK-NEXT: field: Array size=6
420 //CHECK-NEXT: elements: Int 0, Int 1, Int 3, Int 4
421 //CHECK-NEXT: elements: Int 5, Int 9
422 //CHECK-NEXT: field: Int 0
424 consteval const int &f2constintref() {
425 return c.b.i;
428 const int &StructPathRef = f2constintref();
429 //CHECK: VarDecl {{.*}} StructPathRef
430 //CHECK-NEXT: ConstantExpr
431 //CHECK-NEXT: value: LValue &c.b.A::i
433 consteval const std::type_info *ftype_info() {
434 return &typeid(c);
437 const std::type_info *T1 = ftype_info();
438 //CHECK: VarDecl {{.*}} T1
439 //CHECK-NEXT: ConstantExpr
440 //CHECK-NEXT:value: LValue &typeid(LValue::C)
442 consteval const std::type_info *ftype_info2() {
443 return &typeid(Arr.arr[1].Arr[2]);
446 const std::type_info *T2 = ftype_info2();
447 //CHECK: VarDecl {{.*}} T2
448 //CHECK-NEXT: ConstantExpr
449 //CHECK-NEXT: value: LValue &typeid(int)
451 consteval const char *fstring() {
452 return "test";
455 const char *cptr = fstring();
456 //CHECK: VarDecl {{.*}} cptr
457 //CHECK-NEXT: ConstantExpr
458 //CHECK-NEXT: value: LValue &"test"[0]
460 } // namespace LValue
462 #endif