xref: /llvm-project/clang/test/AST/ast-dump-APValue-arithmetic.cpp (revision aee49255074fd4ef38d97e6e70cbfbf2f9fd0fa7)
17a7d50e1SBruno Ricci // Test without serialization:
2f63e3ea5SBruno Ricci // RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value -std=gnu++17 \
3f63e3ea5SBruno Ricci // RUN:            -ast-dump %s -ast-dump-filter Test \
4f63e3ea5SBruno Ricci // RUN: | FileCheck --strict-whitespace --match-full-lines %s
57a7d50e1SBruno Ricci //
67a7d50e1SBruno Ricci // Test with serialization:
77a7d50e1SBruno Ricci // RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value -std=gnu++17 -emit-pch -o %t %s
87a7d50e1SBruno Ricci // RUN: %clang_cc1 -x c++ -triple x86_64-unknown-unknown -Wno-unused-value -std=gnu++17 \
97a7d50e1SBruno Ricci // RUN:           -include-pch %t -ast-dump-all -ast-dump-filter Test /dev/null \
107a7d50e1SBruno Ricci // RUN: | sed -e "s/ <undeserialized declarations>//" -e "s/ imported//" \
117a7d50e1SBruno Ricci // RUN: | FileCheck --strict-whitespace --match-full-lines %s
12f63e3ea5SBruno Ricci 
Test()13f63e3ea5SBruno Ricci void Test() {
14f63e3ea5SBruno Ricci   constexpr int Int = 42;
15f63e3ea5SBruno Ricci   // CHECK:  | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} Int 'const int' constexpr cinit
16f63e3ea5SBruno Ricci   // CHECK-NEXT:  |   |-value: Int 42
17f63e3ea5SBruno Ricci 
18f63e3ea5SBruno Ricci   constexpr __int128 Int128 = (__int128)0xFFFFFFFFFFFFFFFF + (__int128)1;
19f63e3ea5SBruno Ricci   // CHECK:  | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} Int128 'const __int128' constexpr cinit
20f63e3ea5SBruno Ricci   // CHECK-NEXT:  |   |-value: Int 18446744073709551616
21f63e3ea5SBruno Ricci 
22f63e3ea5SBruno Ricci   constexpr float Float = 3.1415f;
23f63e3ea5SBruno Ricci   // CHECK:  | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} Float 'const float' constexpr cinit
24f63e3ea5SBruno Ricci   // CHECK-NEXT:  |   |-value: Float 3.141500e+00
25f63e3ea5SBruno Ricci 
26f63e3ea5SBruno Ricci   constexpr double Double = 3.1415f;
27f63e3ea5SBruno Ricci   // CHECK:  | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} Double 'const double' constexpr cinit
28f63e3ea5SBruno Ricci   // CHECK-NEXT:  |   |-value: Float 3.141500e+00
29f63e3ea5SBruno Ricci 
30f63e3ea5SBruno Ricci   constexpr _Complex int ComplexInt = 42 + 24i;
31f63e3ea5SBruno Ricci   // CHECK:  | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} referenced ComplexInt 'const _Complex int' constexpr cinit
32f63e3ea5SBruno Ricci   // CHECK-NEXT:  |   |-value: ComplexInt 42 + 24i
33f63e3ea5SBruno Ricci 
34f63e3ea5SBruno Ricci   constexpr _Complex float ComplexFloat = 3.1415f + 42i;
35f63e3ea5SBruno Ricci   // CHECK:  | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} referenced ComplexFloat 'const _Complex float' constexpr cinit
36f63e3ea5SBruno Ricci   // CHECK-NEXT:  |   |-value: ComplexFloat 3.141500e+00 + 4.200000e+01i
37f63e3ea5SBruno Ricci 
38f63e3ea5SBruno Ricci   constexpr _Complex int ArrayOfComplexInt[10] = {ComplexInt, ComplexInt, ComplexInt, ComplexInt};
39*2bd84938SDavid Blaikie   // CHECK:  | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} ArrayOfComplexInt 'const _Complex int[10]' constexpr cinit
40f63e3ea5SBruno Ricci   // CHECK-NEXT:  |   |-value: Array size=10
41f63e3ea5SBruno Ricci   // CHECK-NEXT:  |   | |-elements: ComplexInt 42 + 24i, ComplexInt 42 + 24i, ComplexInt 42 + 24i, ComplexInt 42 + 24i
42f63e3ea5SBruno Ricci   // CHECK-NEXT:  |   | `-filler: 6 x ComplexInt 0 + 0i
43f63e3ea5SBruno Ricci 
44f63e3ea5SBruno Ricci   constexpr _Complex float ArrayOfComplexFloat[10] = {ComplexFloat, ComplexFloat, ComplexInt, ComplexInt};
45*2bd84938SDavid Blaikie   // CHECK:    `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} ArrayOfComplexFloat 'const _Complex float[10]' constexpr cinit
46f63e3ea5SBruno Ricci   // CHECK-NEXT:      |-value: Array size=10
47f63e3ea5SBruno Ricci   // CHECK-NEXT:      | |-elements: ComplexFloat 3.141500e+00 + 4.200000e+01i, ComplexFloat 3.141500e+00 + 4.200000e+01i, ComplexFloat 4.200000e+01 + 2.400000e+01i, ComplexFloat 4.200000e+01 + 2.400000e+01i
48f63e3ea5SBruno Ricci   // CHECK-NEXT:      | `-filler: 6 x ComplexFloat 0.000000e+00 + 0.000000e+00i
49f63e3ea5SBruno Ricci }
50