xref: /llvm-project/clang/test/AST/ast-dump-constant-expr.cpp (revision 97af17c5cae64f5fd5e89806e8cf20f50fec30ec)
1e7ce0528SBruno Ricci // Test without serialization:
2e7ce0528SBruno Ricci // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown -ast-dump -ast-dump-filter Test %s \
3e7ce0528SBruno Ricci // RUN: | FileCheck --strict-whitespace --match-full-lines %s
4e7ce0528SBruno Ricci //
5e7ce0528SBruno Ricci // Test with serialization:
6e7ce0528SBruno Ricci // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown -emit-pch -o %t %s
7e7ce0528SBruno Ricci // RUN: %clang_cc1 -x c++ -std=c++20 -triple x86_64-unknown-unknown -include-pch %t \
8e7ce0528SBruno Ricci // RUN: -ast-dump-all -ast-dump-filter Test /dev/null \
97a8c7946SNathan Ridge // RUN: | sed -e "s/ <undeserialized declarations>//" -e "s/ imported//" \
10e7ce0528SBruno Ricci // RUN: | FileCheck --strict-whitespace --match-full-lines %s
11e7ce0528SBruno Ricci 
12e7ce0528SBruno Ricci // FIXME: ASTRecordReader::readAPValue and ASTRecordWriter::AddAPValue
13e7ce0528SBruno Ricci // just give up on some APValue kinds! This *really* should be fixed.
14e7ce0528SBruno Ricci 
15e7ce0528SBruno Ricci struct array_holder {
16e7ce0528SBruno Ricci   int i[2];
17e7ce0528SBruno Ricci };
18e7ce0528SBruno Ricci 
19e7ce0528SBruno Ricci struct S {
20e7ce0528SBruno Ricci   int i = 42;
21e7ce0528SBruno Ricci };
22e7ce0528SBruno Ricci 
23e7ce0528SBruno Ricci union U {
24e7ce0528SBruno Ricci   int i = 42;
25e7ce0528SBruno Ricci   float f;
26e7ce0528SBruno Ricci };
27e7ce0528SBruno Ricci 
28e7ce0528SBruno Ricci struct SU {
29e7ce0528SBruno Ricci   S s[2];
30e7ce0528SBruno Ricci   U u[3];
31e7ce0528SBruno Ricci };
32e7ce0528SBruno Ricci 
test_Int()33e7ce0528SBruno Ricci consteval int test_Int() { return 42; }
test_Float()34e7ce0528SBruno Ricci consteval float test_Float() { return 1.0f; }
test_ComplexInt()35e7ce0528SBruno Ricci consteval _Complex int test_ComplexInt() { return 1+2i; }
test_ComplexFloat()36e7ce0528SBruno Ricci consteval _Complex float test_ComplexFloat() { return 1.2f+3.4fi; }
test_Int128()37e7ce0528SBruno Ricci consteval __int128 test_Int128() { return (__int128)0xFFFFFFFFFFFFFFFF + (__int128)1; }
38e7ce0528SBruno Ricci // FIXME: consteval array_holder test_Array() { return array_holder(); }
39e7ce0528SBruno Ricci // FIXME: consteval S test_Struct() { return S(); }
40e7ce0528SBruno Ricci // FIXME: consteval U test_Union() { return U(); }
41e7ce0528SBruno Ricci // FIXME: consteval SU test_SU() { return SU(); }
42e7ce0528SBruno Ricci 
437a8c7946SNathan Ridge struct Test {
testTest447a8c7946SNathan Ridge   void test() {
45e7ce0528SBruno Ricci     (void)test_Int();
46e7ce0528SBruno Ricci     (void)test_Float();
47e7ce0528SBruno Ricci     (void)test_ComplexInt();
48e7ce0528SBruno Ricci     (void)test_ComplexFloat();
49e7ce0528SBruno Ricci     (void)test_Int128();
50e7ce0528SBruno Ricci     //(void) test_Array();
51e7ce0528SBruno Ricci     //(void) test_Struct();
52e7ce0528SBruno Ricci     //(void) test_Union();
53e7ce0528SBruno Ricci     //(void) test_SU();
54e7ce0528SBruno Ricci   }
557a8c7946SNathan Ridge 
consteval_methodTest567a8c7946SNathan Ridge   consteval void consteval_method() {}
577a8c7946SNathan Ridge };
587a8c7946SNathan Ridge 
59e7ce0528SBruno Ricci // CHECK:Dumping Test:
607a8c7946SNathan Ridge // CHECK-NEXT:CXXRecordDecl {{.*}} <{{.*}}ast-dump-constant-expr.cpp:43:1, line:57:1> line:43:8 struct Test definition
61*97af17c5SIain Sandoe // CHECK:|-CXXMethodDecl {{.*}} <line:44:3, line:54:3> line:44:8 test 'void ()' implicit-inline
627a8c7946SNathan Ridge // CHECK-NEXT:| `-CompoundStmt {{.*}} <col:15, line:54:3>
637a8c7946SNathan Ridge // CHECK-NEXT:|   |-CStyleCastExpr {{.*}} <line:45:5, col:20> 'void' <ToVoid>
647a8c7946SNathan Ridge // CHECK-NEXT:|   | `-ConstantExpr {{.*}} <col:11, col:20> 'int'
657a8c7946SNathan Ridge // CHECK-NEXT:|   |   |-value: Int 42
667a8c7946SNathan Ridge // CHECK-NEXT:|   |   `-CallExpr {{.*}} <col:11, col:20> 'int'
677a8c7946SNathan Ridge // CHECK-NEXT:|   |     `-ImplicitCastExpr {{.*}} <col:11> 'int (*)()' <FunctionToPointerDecay>
687a8c7946SNathan Ridge // CHECK-NEXT:|   |       `-DeclRefExpr {{.*}} <col:11> 'int ()' lvalue Function {{.*}} 'test_Int' 'int ()'
697a8c7946SNathan Ridge // CHECK-NEXT:|   |-CStyleCastExpr {{.*}} <line:46:5, col:22> 'void' <ToVoid>
707a8c7946SNathan Ridge // CHECK-NEXT:|   | `-ConstantExpr {{.*}} <col:11, col:22> 'float'
717a8c7946SNathan Ridge // CHECK-NEXT:|   |   |-value: Float 1.000000e+00
727a8c7946SNathan Ridge // CHECK-NEXT:|   |   `-CallExpr {{.*}} <col:11, col:22> 'float'
737a8c7946SNathan Ridge // CHECK-NEXT:|   |     `-ImplicitCastExpr {{.*}} <col:11> 'float (*)()' <FunctionToPointerDecay>
747a8c7946SNathan Ridge // CHECK-NEXT:|   |       `-DeclRefExpr {{.*}} <col:11> 'float ()' lvalue Function {{.*}} 'test_Float' 'float ()'
757a8c7946SNathan Ridge // CHECK-NEXT:|   |-CStyleCastExpr {{.*}} <line:47:5, col:27> 'void' <ToVoid>
767a8c7946SNathan Ridge // CHECK-NEXT:|   | `-ConstantExpr {{.*}} <col:11, col:27> '_Complex int'
777a8c7946SNathan Ridge // CHECK-NEXT:|   |   |-value: ComplexInt 1 + 2i
787a8c7946SNathan Ridge // CHECK-NEXT:|   |   `-CallExpr {{.*}} <col:11, col:27> '_Complex int'
797a8c7946SNathan Ridge // CHECK-NEXT:|   |     `-ImplicitCastExpr {{.*}} <col:11> '_Complex int (*)()' <FunctionToPointerDecay>
807a8c7946SNathan Ridge // CHECK-NEXT:|   |       `-DeclRefExpr {{.*}} <col:11> '_Complex int ()' lvalue Function {{.*}} 'test_ComplexInt' '_Complex int ()'
817a8c7946SNathan Ridge // CHECK-NEXT:|   |-CStyleCastExpr {{.*}} <line:48:5, col:29> 'void' <ToVoid>
827a8c7946SNathan Ridge // CHECK-NEXT:|   | `-ConstantExpr {{.*}} <col:11, col:29> '_Complex float'
837a8c7946SNathan Ridge // CHECK-NEXT:|   |   |-value: ComplexFloat 1.200000e+00 + 3.400000e+00i
847a8c7946SNathan Ridge // CHECK-NEXT:|   |   `-CallExpr {{.*}} <col:11, col:29> '_Complex float'
857a8c7946SNathan Ridge // CHECK-NEXT:|   |     `-ImplicitCastExpr {{.*}} <col:11> '_Complex float (*)()' <FunctionToPointerDecay>
867a8c7946SNathan Ridge // CHECK-NEXT:|   |       `-DeclRefExpr {{.*}} <col:11> '_Complex float ()' lvalue Function {{.*}} 'test_ComplexFloat' '_Complex float ()'
877a8c7946SNathan Ridge // CHECK-NEXT:|   `-CStyleCastExpr {{.*}} <line:49:5, col:23> 'void' <ToVoid>
887a8c7946SNathan Ridge // CHECK-NEXT:|     `-ConstantExpr {{.*}} <col:11, col:23> '__int128'
897a8c7946SNathan Ridge // CHECK-NEXT:|       |-value: Int 18446744073709551616
907a8c7946SNathan Ridge // CHECK-NEXT:|       `-CallExpr {{.*}} <col:11, col:23> '__int128'
917a8c7946SNathan Ridge // CHECK-NEXT:|         `-ImplicitCastExpr {{.*}} <col:11> '__int128 (*)()' <FunctionToPointerDecay>
927a8c7946SNathan Ridge // CHECK-NEXT:|           `-DeclRefExpr {{.*}} <col:11> '__int128 ()' lvalue Function {{.*}} 'test_Int128' '__int128 ()'
93*97af17c5SIain Sandoe // CHECK-NEXT:`-CXXMethodDecl {{.*}} <line:56:3, col:38> col:18 consteval consteval_method 'void ()' implicit-inline
94