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
11 consteval
int fint() {
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.
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
72 constexpr A(B b
, int I
, double D
, C _c
) : B(b
), i(I
), d(D
), c(_c
) {}
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
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
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
130 double d
= 67890.09876;
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)));
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
176 A a
{567890, 9876.5678f
};
183 U Unique_Union1
= fU1();
184 //CHECK: VarDecl {{.*}} Unique_Union
185 //CHECK-NEXT: ConstantExpr
186 //CHECK-NEXT: value: Union .i Int 0
192 U Unique_Union2
= fU();
193 //CHECK: VarDecl {{.*}} Unique_Union
194 //CHECK-NEXT: ConstantExpr
195 //CHECK-NEXT: value: Union .a
197 //CHECK-NEXT: fields: Int 567890, Float 9.876567e+03
201 namespace MemberPointer
{
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
236 consteval
auto fmem_ptr2() {
240 auto MemberPointer2
= fmem_ptr2();
241 //CHECK: VarDecl {{.*}} MemberPointer2
242 //CHECK-NEXT: ConstantExpr
243 //CHECK-NEXT: value: MemberPointer &B1::f
245 } // namespace MemberPointer
255 consteval
const int &fg_ref() {
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() {
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() {
277 const int *ptr2
= fnull_ptr();
278 //CHECK: VarDecl {{.*}} ptr2
279 //CHECK-NEXT: ConstantExpr
280 //CHECK-NEXT: value: LValue nullptr
284 consteval
auto ffunc_ptr() {
288 int (*func_ptr
)() = ffunc_ptr();
289 //CHECK: VarDecl {{.*}} func_ptr
290 //CHECK-NEXT: ConstantExpr {{.*}}
291 //CHECK-NEXT: value: LValue &fconst
294 int Arr
[6] = {0, 1, 3, 4, 5, 9};
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() {
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]
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() {
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() {
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() {
455 const char *cptr
= fstring();
456 //CHECK: VarDecl {{.*}} cptr
457 //CHECK-NEXT: ConstantExpr
458 //CHECK-NEXT: value: LValue &"test"[0]
460 } // namespace LValue