1 // Test without serialization:
2 // RUN: %clang_cc1 -std=c++23 -triple x86_64-linux-gnu -fcxx-exceptions -ast-dump %s \
3 // RUN: | FileCheck -strict-whitespace %s
5 // Test with serialization:
6 // RUN: %clang_cc1 -std=c++23 -triple x86_64-linux-gnu -fcxx-exceptions -emit-pch -o %t %s
7 // RUN: %clang_cc1 -x c++ -std=c++23 -triple x86_64-linux-gnu -fcxx-exceptions -include-pch %t -ast-dump-all /dev/null \
8 // RUN: | sed -e "s/ <undeserialized declarations>//" -e "s/ imported//" \
9 // RUN: | FileCheck -strict-whitespace %s
18 void (*f
)() = &function
;
19 // CHECK: DeclRefExpr{{.*}} (UsingShadow{{.*}}function
21 // CHECK: DeclRefExpr{{.*}} (UsingShadow{{.*}}Variable
24 // CHECK: FunctionDecl {{.*}} TestCatch1
27 // CHECK-NEXT: CompoundStmt
30 // CHECK-NEXT: CXXCatchStmt
31 // CHECK-NEXT: VarDecl {{.*}} x
32 // CHECK-NEXT: CompoundStmt
37 // CHECK: FunctionDecl {{.*}} TestCatch2
40 // CHECK-NEXT: CompoundStmt
43 // CHECK-NEXT: CXXCatchStmt
45 // CHECK-NEXT: CompoundStmt
50 void TestAllocationExprs() {
59 // CHECK: FunctionDecl {{.*}} TestAllocationExprs
60 // CHECK: CXXNewExpr {{.*}} 'int *' Function {{.*}} 'operator new'
61 // CHECK: CXXDeleteExpr {{.*}} 'void' Function {{.*}} 'operator delete'
62 // CHECK: CXXNewExpr {{.*}} 'int *' array Function {{.*}} 'operator new[]'
63 // CHECK: CXXDeleteExpr {{.*}} 'void' array Function {{.*}} 'operator delete[]'
64 // CHECK: CXXNewExpr {{.*}} 'int *' global Function {{.*}} 'operator new'
65 // CHECK: CXXDeleteExpr {{.*}} 'void' global Function {{.*}} 'operator delete'
67 // Don't crash on dependent exprs that haven't been resolved yet.
69 void TestDependentAllocationExpr() {
73 // CHECK: FunctionTemplateDecl {{.*}} TestDependentAllocationExpr
74 // CHECK: CXXNewExpr {{.*'T \*'$}}
75 // CHECK: CXXDeleteExpr {{.*'void'$}}
78 class DependentScopeMemberExprWrapper
{
83 void TestDependentScopeMemberExpr() {
84 DependentScopeMemberExprWrapper
<T
> obj
;
88 // CHECK: FunctionTemplateDecl {{.*}} TestDependentScopeMemberExpr
89 // CHECK: CXXDependentScopeMemberExpr {{.*}} lvalue .member
90 // CHECK: CXXDependentScopeMemberExpr {{.*}} lvalue ->member
97 void TestUnionInitList()
100 // CHECK: VarDecl {{.+}} <col:3, col:15> col:5 us 'U[3]' cinit
101 // CHECK-NEXT: `-InitListExpr {{.+}} <col:13, col:15> 'U[3]'
102 // CHECK-NEXT: |-array_filler: InitListExpr {{.+}} <col:15> 'U' field Field {{.+}} 'i' 'int'
103 // CHECK-NEXT: `-InitListExpr {{.+}} <col:14> 'U' field Field {{.+}} 'i' 'int'
104 // CHECK-NEXT: `-IntegerLiteral {{.+}} <col:14> 'int' 1
107 void TestSwitch(int i
) {
110 // CHECK: SwitchStmt 0x{{[^ ]*}} <line:[[@LINE-2]]:3, line:[[@LINE-1]]:5> has_init
111 // CHECK-NEXT: DeclStmt
112 // CHECK-NEXT: VarDecl 0x{{[^ ]*}} <col:11, col:15> col:15 a 'int'
113 // CHECK-NEXT: ImplicitCastExpr
114 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:18> 'int' lvalue ParmVar 0x{{[^ ]*}} 'i' 'int'
115 // CHECK-NEXT: NullStmt
118 void TestIf(bool b
) {
121 // CHECK: IfStmt 0x{{[^ ]*}} <line:[[@LINE-2]]:3, line:[[@LINE-1]]:5> has_init
122 // CHECK-NEXT: DeclStmt
123 // CHECK-NEXT: VarDecl 0x{{[^ ]*}} <col:7, col:15> col:11 i 'int' cinit
124 // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:15> 'int' 12
125 // CHECK-NEXT: ImplicitCastExpr
126 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:19> 'bool' lvalue ParmVar 0x{{[^ ]*}} 'b' 'bool'
127 // CHECK-NEXT: NullStmt
129 if constexpr (sizeof(b
) == 1)
131 // CHECK: IfStmt 0x{{[^ ]*}} <line:[[@LINE-2]]:3, line:[[@LINE-1]]:5>
132 // CHECK-NEXT: ConstantExpr 0x{{[^ ]*}} <line:[[@LINE-3]]:17, col:30> 'bool'
133 // CHECK-NEXT: value: Int 1
134 // CHECK-NEXT: BinaryOperator
135 // CHECK-NEXT: UnaryExprOrTypeTraitExpr
136 // CHECK-NEXT: ParenExpr
137 // CHECK-NEXT: DeclRefExpr
138 // CHECK-NEXT: ImplicitCastExpr
139 // CHECK-NEXT: IntegerLiteral
140 // CHECK-NEXT: NullStmt
142 if constexpr (sizeof(b
) == 1)
146 // CHECK: IfStmt 0x{{[^ ]*}} <line:[[@LINE-4]]:3, line:[[@LINE-1]]:5> has_else
147 // CHECK-NEXT: ConstantExpr 0x{{[^ ]*}} <line:[[@LINE-5]]:17, col:30> 'bool'
148 // CHECK-NEXT: value: Int 1
149 // CHECK-NEXT: BinaryOperator
150 // CHECK-NEXT: UnaryExprOrTypeTraitExpr
151 // CHECK-NEXT: ParenExpr
152 // CHECK-NEXT: DeclRefExpr
153 // CHECK-NEXT: ImplicitCastExpr
154 // CHECK-NEXT: IntegerLiteral
155 // CHECK-NEXT: NullStmt
156 // CHECK-NEXT: NullStmt
159 // CHECK: IfStmt 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:17> consteval
160 // CHECK-NEXT: CompoundStmt
164 // CHECK: IfStmt 0x{{[^ ]*}} <line:[[@LINE-2]]:3, line:[[@LINE-1]]:9> has_else !consteval
165 // CHECK-NEXT: CompoundStmt
166 // CHECK-NEXT: CompoundStmt
174 void TestIteration() {
175 for (int i
= 0; int j
= i
; ++i
)
177 // CHECK: ForStmt 0x{{[^ ]*}} <line:[[@LINE-2]]:3, line:[[@LINE-1]]:5>
178 // CHECK-NEXT: DeclStmt
179 // CHECK-NEXT: VarDecl 0x{{[^ ]*}} <col:8, col:16> col:12 used i 'int' cinit
180 // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:16> 'int' 0
181 // CHECK-NEXT: DeclStmt
182 // CHECK-NEXT: VarDecl 0x{{[^ ]*}} <col:19, col:27> col:23 used j 'int' cinit
183 // CHECK-NEXT: ImplicitCastExpr
184 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:27> 'int' lvalue Var 0x{{[^ ]*}} 'i' 'int'
185 // CHECK-NEXT: ImplicitCastExpr 0x{{[^ ]*}} <col:23> 'bool' <IntegralToBoolean>
186 // CHECK-NEXT: ImplicitCastExpr 0x{{[^ ]*}} <col:23> 'int' <LValueToRValue>
187 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:23> 'int' lvalue Var 0x{{[^ ]*}} 'j' 'int'
188 // CHECK-NEXT: UnaryOperator 0x{{[^ ]*}} <col:30, col:32> 'int' lvalue prefix '++'
189 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:32> 'int' lvalue Var 0x{{[^ ]*}} 'i' 'int'
190 // CHECK-NEXT: NullStmt
195 // CHECK: CXXForRangeStmt 0x{{[^ ]*}} <line:[[@LINE-2]]:3, line:[[@LINE-1]]:5>
196 // CHECK-NEXT: <<<NULL>>>
197 // CHECK-NEXT: DeclStmt
198 // CHECK-NEXT: VarDecl 0x{{[^ ]*}} <col:16> col:16 implicit used __range1 'int (&)[10]' cinit
199 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:16> 'int[10]' lvalue Var 0x{{[^ ]*}} 'vals' 'int[10]'
200 // CHECK-NEXT: DeclStmt
201 // CHECK-NEXT: VarDecl 0x{{[^ ]*}} <col:14> col:14 implicit used __begin1 'int *' cinit
202 // CHECK-NEXT: ImplicitCastExpr
203 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:14> 'int[10]' lvalue Var 0x{{[^ ]*}} '__range1' 'int (&)[10]'
204 // CHECK-NEXT: DeclStmt
205 // CHECK-NEXT: VarDecl 0x{{[^ ]*}} <col:14, col:16> col:14 implicit used __end1 'int *' cinit
206 // CHECK-NEXT: BinaryOperator 0x{{[^ ]*}} <col:14, col:16> 'int *' '+'
207 // CHECK-NEXT: ImplicitCastExpr
208 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:14> 'int[10]' lvalue Var 0x{{[^ ]*}} '__range1' 'int (&)[10]'
209 // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:16> 'long' 10
210 // CHECK-NEXT: BinaryOperator 0x{{[^ ]*}} <col:14> 'bool' '!='
211 // CHECK-NEXT: ImplicitCastExpr
212 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:14> 'int *' lvalue Var 0x{{[^ ]*}} '__begin1' 'int *'
213 // CHECK-NEXT: ImplicitCastExpr
214 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:14> 'int *' lvalue Var 0x{{[^ ]*}} '__end1' 'int *'
215 // CHECK-NEXT: UnaryOperator 0x{{[^ ]*}} <col:14> 'int *' lvalue prefix '++'
216 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:14> 'int *' lvalue Var 0x{{[^ ]*}} '__begin1' 'int *'
217 // CHECK-NEXT: DeclStmt
218 // CHECK-NEXT: VarDecl 0x{{[^ ]*}} <col:8, col:14> col:12 v 'int' cinit
219 // CHECK-NEXT: ImplicitCastExpr
220 // CHECK-NEXT: UnaryOperator 0x{{[^ ]*}} <col:14> 'int' lvalue prefix '*' cannot overflow
221 // CHECK-NEXT: ImplicitCastExpr
222 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:14> 'int *' lvalue Var 0x{{[^ ]*}} '__begin1' 'int *'
223 // CHECK-NEXT: NullStmt
228 // CHECK: CXXForRangeStmt 0x{{[^ ]*}} <line:[[@LINE-2]]:3, line:[[@LINE-1]]:5>
229 // CHECK-NEXT: <<<NULL>>>
230 // CHECK-NEXT: DeclStmt
231 // CHECK-NEXT: VarDecl 0x{{[^ ]*}} <col:16> col:16 implicit used __range1 'Container &' cinit
232 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:16> 'Container' lvalue Var 0x{{[^ ]*}} 'C' 'Container'
233 // CHECK-NEXT: DeclStmt
234 // CHECK-NEXT: VarDecl 0x{{[^ ]*}} <col:14> col:14 implicit used __begin1 'int *' cinit
235 // CHECK-NEXT: CXXMemberCallExpr 0x{{[^ ]*}} <col:14> 'int *'
236 // CHECK-NEXT: MemberExpr 0x{{[^ ]*}} <col:14> '<bound member function type>' .begin 0x{{[^ ]*}}
237 // CHECK-NEXT: ImplicitCastExpr
238 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:14> 'Container' lvalue Var 0x{{[^ ]*}} '__range1' 'Container &'
239 // CHECK-NEXT: DeclStmt
240 // CHECK-NEXT: VarDecl 0x{{[^ ]*}} <col:14> col:14 implicit used __end1 'int *' cinit
241 // CHECK-NEXT: CXXMemberCallExpr 0x{{[^ ]*}} <col:14> 'int *'
242 // CHECK-NEXT: MemberExpr 0x{{[^ ]*}} <col:14> '<bound member function type>' .end 0x{{[^ ]*}}
243 // CHECK-NEXT: ImplicitCastExpr
244 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:14> 'Container' lvalue Var 0x{{[^ ]*}} '__range1' 'Container &'
245 // CHECK-NEXT: BinaryOperator 0x{{[^ ]*}} <col:14> 'bool' '!='
246 // CHECK-NEXT: ImplicitCastExpr
247 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:14> 'int *' lvalue Var 0x{{[^ ]*}} '__begin1' 'int *'
248 // CHECK-NEXT: ImplicitCastExpr
249 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:14> 'int *' lvalue Var 0x{{[^ ]*}} '__end1' 'int *'
250 // CHECK-NEXT: UnaryOperator 0x{{[^ ]*}} <col:14> 'int *' lvalue prefix '++'
251 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:14> 'int *' lvalue Var 0x{{[^ ]*}} '__begin1' 'int *'
252 // CHECK-NEXT: DeclStmt
253 // CHECK-NEXT: VarDecl 0x{{[^ ]*}} <col:8, col:14> col:12 v 'int' cinit
254 // CHECK-NEXT: ImplicitCastExpr
255 // CHECK-NEXT: UnaryOperator 0x{{[^ ]*}} <col:14> 'int' lvalue prefix '*' cannot overflow
256 // CHECK-NEXT: ImplicitCastExpr
257 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:14> 'int *' lvalue Var 0x{{[^ ]*}} '__begin1' 'int *'
258 // CHECK-NEXT: NullStmt
260 for (int a
; int v
: vals
)
262 // CHECK: CXXForRangeStmt 0x{{[^ ]*}} <line:[[@LINE-2]]:3, line:[[@LINE-1]]:5>
263 // CHECK-NEXT: DeclStmt
264 // CHECK-NEXT: VarDecl 0x{{[^ ]*}} <col:8, col:12> col:12 a 'int'
265 // CHECK-NEXT: DeclStmt
266 // CHECK-NEXT: VarDecl 0x{{[^ ]*}} <col:23> col:23 implicit used __range1 'int (&)[10]' cinit
267 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:23> 'int[10]' lvalue Var 0x{{[^ ]*}} 'vals' 'int[10]'
268 // CHECK-NEXT: DeclStmt
269 // CHECK-NEXT: VarDecl 0x{{[^ ]*}} <col:21> col:21 implicit used __begin1 'int *' cinit
270 // CHECK-NEXT: ImplicitCastExpr
271 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:21> 'int[10]' lvalue Var 0x{{[^ ]*}} '__range1' 'int (&)[10]'
272 // CHECK-NEXT: DeclStmt
273 // CHECK-NEXT: VarDecl 0x{{[^ ]*}} <col:21, col:23> col:21 implicit used __end1 'int *' cinit
274 // CHECK-NEXT: BinaryOperator 0x{{[^ ]*}} <col:21, col:23> 'int *' '+'
275 // CHECK-NEXT: ImplicitCastExpr
276 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:21> 'int[10]' lvalue Var 0x{{[^ ]*}} '__range1' 'int (&)[10]'
277 // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:23> 'long' 10
278 // CHECK-NEXT: BinaryOperator 0x{{[^ ]*}} <col:21> 'bool' '!='
279 // CHECK-NEXT: ImplicitCastExpr
280 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:21> 'int *' lvalue Var 0x{{[^ ]*}} '__begin1' 'int *'
281 // CHECK-NEXT: ImplicitCastExpr
282 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:21> 'int *' lvalue Var 0x{{[^ ]*}} '__end1' 'int *'
283 // CHECK-NEXT: UnaryOperator 0x{{[^ ]*}} <col:21> 'int *' lvalue prefix '++'
284 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:21> 'int *' lvalue Var 0x{{[^ ]*}} '__begin1' 'int *'
285 // CHECK-NEXT: DeclStmt
286 // CHECK-NEXT: VarDecl 0x{{[^ ]*}} <col:15, col:21> col:19 v 'int' cinit
287 // CHECK-NEXT: ImplicitCastExpr
288 // CHECK-NEXT: UnaryOperator 0x{{[^ ]*}} <col:21> 'int' lvalue prefix '*' cannot overflow
289 // CHECK-NEXT: ImplicitCastExpr
290 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:21> 'int *' lvalue Var 0x{{[^ ]*}} '__begin1' 'int *'
291 // CHECK-NEXT: NullStmt