Commit 3cfdef3
[Clang] Fix the for statement disappearing in AST when an error occurs in the conditional expression of the for statement (#65381)
Consider:
```
constexpr int f() {
int sum = 0;
for (int i = 0; undefined_var; ++i) {
sum += i;
}
return sum;
}
static_assert(f());
```
The AST before this patch:
```
|-FunctionDecl <line:1:1, line:7:1> line:1:15 used constexpr f 'int ()' implicit-inline
| `-CompoundStmt <col:19, line:7:1>
| |-DeclStmt <line:2:5, col:16>
| | `-VarDecl <col:5, col:15> col:9 used sum 'int' cinit
| | `-IntegerLiteral <col:15> 'int' 0
| `-ReturnStmt <line:6:5, col:12>
| `-ImplicitCastExpr <col:12> 'int' <LValueToRValue>
| `-DeclRefExpr <col:12> 'int' lvalue Var 0xb870518 'sum' 'int'
```
The AST after this patch:
```
|-FunctionDecl 0x11d0f63f8 <./main.cpp:1:1, line:7:1> line:1:15 used constexpr f 'int ()' implicit-inline
| `-CompoundStmt 0x11d110880 <col:19, line:7:1>
| |-DeclStmt 0x11d0f65c8 <line:2:5, col:16>
| | `-VarDecl 0x11d0f6528 <col:5, col:15> col:9 used sum 'int' cinit
| | `-IntegerLiteral 0x11d0f6590 <col:15> 'int' 0
| |-ForStmt 0x11d110800 <line:3:5, line:5:5>
| | |-DeclStmt 0x11d0f66a0 <line:3:10, col:19>
| | | `-VarDecl 0x11d0f6600 <col:10, col:18> col:14 used i 'int' cinit
| | | `-IntegerLiteral 0x11d0f6668 <col:18> 'int' 0
| | |-<<<NULL>>>
| | |-RecoveryExpr 0x11d0f66e8 <col:21> 'bool' contains-errors
| | |-UnaryOperator 0x11d0f6728 <col:36, col:38> 'int' lvalue prefix '++'
| | | `-DeclRefExpr 0x11d0f6708 <col:38> 'int' lvalue Var 0x11d0f6600 'i' 'int'
| | `-CompoundStmt 0x11d0f67c8 <col:41, line:5:5>
| | `-CompoundAssignOperator 0x11d0f6798 <line:4:9, col:16> 'int' lvalue '+=' ComputeLHSTy='int' ComputeResultTy='int'
| | |-DeclRefExpr 0x11d0f6740 <col:9> 'int' lvalue Var 0x11d0f6528 'sum' 'int'
| | `-ImplicitCastExpr 0x11d0f6780 <col:16> 'int' <LValueToRValue>
| | `-DeclRefExpr 0x11d0f6760 <col:16> 'int' lvalue Var 0x11d0f6600 'i' 'int'
| `-ReturnStmt 0x11d110870 <line:6:5, col:12>
| `-ImplicitCastExpr 0x11d110858 <col:12> 'int' <LValueToRValue>
| `-DeclRefExpr 0x11d110838 <col:12> 'int' lvalue Var 0x11d0f6528 'sum' 'int'
```
---------
Co-authored-by: Shafik Yaghmour <[email protected]>1 parent 123bf08 commit 3cfdef3
File tree
3 files changed
+33
-2
lines changed- clang
- lib/Parse
- test
- AST
- SemaCXX
3 files changed
+33
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2158 | 2158 | | |
2159 | 2159 | | |
2160 | 2160 | | |
| 2161 | + | |
| 2162 | + | |
2161 | 2163 | | |
2162 | | - | |
| 2164 | + | |
2163 | 2165 | | |
2164 | 2166 | | |
2165 | | - | |
| 2167 | + | |
2166 | 2168 | | |
2167 | 2169 | | |
2168 | 2170 | | |
| |||
2178 | 2180 | | |
2179 | 2181 | | |
2180 | 2182 | | |
| 2183 | + | |
| 2184 | + | |
| 2185 | + | |
| 2186 | + | |
| 2187 | + | |
| 2188 | + | |
| 2189 | + | |
| 2190 | + | |
| 2191 | + | |
| 2192 | + | |
| 2193 | + | |
| 2194 | + | |
| 2195 | + | |
2181 | 2196 | | |
2182 | 2197 | | |
2183 | 2198 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
432 | 432 | | |
433 | 433 | | |
434 | 434 | | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
| 109 | + | |
0 commit comments