Skip to content

Commit 756affa

Browse files
committed
Rust: Fix bugs in LetExprTree and MethodCallExprTree
1 parent 2f14ec9 commit 756affa

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
lines changed

rust/ql/lib/codeql/rust/controlflow/internal/ControlFlowGraphImpl.qll

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,14 @@ class ItemTree extends LeafTree, Item { }
296296
// `LetExpr` is a pre-order tree such that the pattern itself ends up
297297
// dominating successors in the graph in the same way that patterns do in
298298
// `match` expressions.
299-
class LetExprTree extends StandardPreOrderTree instanceof LetExpr {
300-
override AstNode getChildNode(int i) { i = 0 and result = super.getPat() }
299+
class LetExprTree extends StandardPreOrderTree, LetExpr {
300+
override AstNode getChildNode(int i) {
301+
i = 0 and
302+
result = this.getExpr()
303+
or
304+
i = 1 and
305+
result = this.getPat()
306+
}
301307
}
302308

303309
class LetStmtTree extends PreOrderTree, LetStmt {
@@ -479,10 +485,12 @@ class MatchExprTree extends PostOrderTree instanceof MatchExpr {
479485
}
480486
}
481487

482-
class MethodCallExprTree extends StandardPostOrderTree instanceof MethodCallExpr {
488+
class MethodCallExprTree extends StandardPostOrderTree, MethodCallExpr {
483489
override AstNode getChildNode(int i) {
484-
result = super.getReceiver() and
485-
result = super.getArgList().getArg(i + 1)
490+
i = 0 and
491+
result = this.getReceiver()
492+
or
493+
result = this.getArgList().getArg(i + 1)
486494
}
487495
}
488496

rust/ql/test/library-tests/controlflow/Cfg.expected

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,12 @@ edges
157157
| test.rs:80:24:80:28 | RangeExpr | test.rs:80:13:80:20 | iter | |
158158
| test.rs:80:27:80:28 | 10 | test.rs:80:24:80:28 | RangeExpr | |
159159
| test.rs:81:9:85:9 | WhileExpr | test.rs:79:25:86:5 | BlockExpr | |
160-
| test.rs:81:15:81:39 | LetExpr | test.rs:81:19:81:25 | TupleStructPat | |
160+
| test.rs:81:15:81:39 | LetExpr | test.rs:81:29:81:32 | iter | |
161161
| test.rs:81:19:81:25 | TupleStructPat | test.rs:81:9:85:9 | WhileExpr | no-match |
162162
| test.rs:81:19:81:25 | TupleStructPat | test.rs:81:24:81:24 | x | match |
163163
| test.rs:81:24:81:24 | x | test.rs:82:17:82:17 | PathExpr | match |
164+
| test.rs:81:29:81:32 | iter | test.rs:81:29:81:39 | MethodCallExpr | |
165+
| test.rs:81:29:81:39 | MethodCallExpr | test.rs:81:19:81:25 | TupleStructPat | |
164166
| test.rs:81:41:85:9 | BlockExpr | test.rs:81:15:81:39 | LetExpr | |
165167
| test.rs:82:13:84:13 | IfExpr | test.rs:81:41:85:9 | BlockExpr | |
166168
| test.rs:82:17:82:17 | PathExpr | test.rs:82:21:82:21 | 5 | |
@@ -233,10 +235,11 @@ edges
233235
| test.rs:113:25:113:38 | Param | test.rs:114:12:114:26 | LetExpr | |
234236
| test.rs:113:48:119:5 | BlockExpr | test.rs:113:5:119:5 | exit test_if_let_else (normal) | |
235237
| test.rs:114:9:118:9 | IfExpr | test.rs:113:48:119:5 | BlockExpr | |
236-
| test.rs:114:12:114:26 | LetExpr | test.rs:114:16:114:22 | TupleStructPat | |
238+
| test.rs:114:12:114:26 | LetExpr | test.rs:114:26:114:26 | a | |
237239
| test.rs:114:16:114:22 | TupleStructPat | test.rs:114:21:114:21 | n | match |
238240
| test.rs:114:16:114:22 | TupleStructPat | test.rs:117:13:117:13 | 0 | no-match |
239241
| test.rs:114:21:114:21 | n | test.rs:115:13:115:13 | n | match |
242+
| test.rs:114:26:114:26 | a | test.rs:114:16:114:22 | TupleStructPat | |
240243
| test.rs:114:28:116:9 | BlockExpr | test.rs:114:9:118:9 | IfExpr | |
241244
| test.rs:115:13:115:13 | n | test.rs:114:28:116:9 | BlockExpr | |
242245
| test.rs:116:16:118:9 | BlockExpr | test.rs:114:9:118:9 | IfExpr | |
@@ -248,10 +251,11 @@ edges
248251
| test.rs:121:43:126:5 | BlockExpr | test.rs:121:5:126:5 | exit test_if_let (normal) | |
249252
| test.rs:122:9:124:9 | ExprStmt | test.rs:122:12:122:26 | LetExpr | |
250253
| test.rs:122:9:124:9 | IfExpr | test.rs:125:9:125:9 | 0 | |
251-
| test.rs:122:12:122:26 | LetExpr | test.rs:122:16:122:22 | TupleStructPat | |
254+
| test.rs:122:12:122:26 | LetExpr | test.rs:122:26:122:26 | a | |
252255
| test.rs:122:16:122:22 | TupleStructPat | test.rs:122:9:124:9 | IfExpr | no-match |
253256
| test.rs:122:16:122:22 | TupleStructPat | test.rs:122:21:122:21 | n | match |
254257
| test.rs:122:21:122:21 | n | test.rs:123:13:123:13 | n | match |
258+
| test.rs:122:26:122:26 | a | test.rs:122:16:122:22 | TupleStructPat | |
255259
| test.rs:122:28:124:9 | BlockExpr | test.rs:122:9:124:9 | IfExpr | |
256260
| test.rs:123:13:123:13 | n | test.rs:122:28:124:9 | BlockExpr | |
257261
| test.rs:125:9:125:9 | 0 | test.rs:121:43:126:5 | BlockExpr | |

rust/ql/test/library-tests/variables/Cfg.expected

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,11 @@ edges
149149
| variables.rs:74:19:74:40 | CallExpr | variables.rs:74:14:74:41 | CallExpr | |
150150
| variables.rs:74:32:74:39 | "Hello!" | variables.rs:74:19:74:40 | CallExpr | |
151151
| variables.rs:76:5:79:5 | IfExpr | variables.rs:73:19:80:1 | BlockExpr | |
152-
| variables.rs:76:8:77:12 | LetExpr | variables.rs:76:12:76:23 | TupleStructPat | |
152+
| variables.rs:76:8:77:12 | LetExpr | variables.rs:77:11:77:12 | s1 | |
153153
| variables.rs:76:12:76:23 | TupleStructPat | variables.rs:76:5:79:5 | IfExpr | no-match |
154154
| variables.rs:76:12:76:23 | TupleStructPat | variables.rs:76:17:76:22 | s2 | match |
155155
| variables.rs:76:17:76:22 | s2 | variables.rs:78:9:78:22 | ExprStmt | match |
156+
| variables.rs:77:11:77:12 | s1 | variables.rs:76:12:76:23 | TupleStructPat | |
156157
| variables.rs:77:14:79:5 | BlockExpr | variables.rs:76:5:79:5 | IfExpr | |
157158
| variables.rs:78:9:78:17 | PathExpr | variables.rs:78:19:78:20 | s2 | |
158159
| variables.rs:78:9:78:21 | CallExpr | variables.rs:77:14:79:5 | BlockExpr | |
@@ -184,10 +185,11 @@ edges
184185
| variables.rs:91:19:91:40 | CallExpr | variables.rs:91:14:91:41 | CallExpr | |
185186
| variables.rs:91:32:91:39 | "Hello!" | variables.rs:91:19:91:40 | CallExpr | |
186187
| variables.rs:93:5:96:5 | WhileExpr | variables.rs:90:19:97:1 | BlockExpr | |
187-
| variables.rs:93:11:94:12 | LetExpr | variables.rs:93:15:93:26 | TupleStructPat | |
188+
| variables.rs:93:11:94:12 | LetExpr | variables.rs:94:11:94:12 | s1 | |
188189
| variables.rs:93:15:93:26 | TupleStructPat | variables.rs:93:5:96:5 | WhileExpr | no-match |
189190
| variables.rs:93:15:93:26 | TupleStructPat | variables.rs:93:20:93:25 | s2 | match |
190191
| variables.rs:93:20:93:25 | s2 | variables.rs:95:9:95:22 | ExprStmt | match |
192+
| variables.rs:94:11:94:12 | s1 | variables.rs:93:15:93:26 | TupleStructPat | |
191193
| variables.rs:94:14:96:5 | BlockExpr | variables.rs:93:11:94:12 | LetExpr | |
192194
| variables.rs:95:9:95:17 | PathExpr | variables.rs:95:19:95:20 | s2 | |
193195
| variables.rs:95:9:95:21 | CallExpr | variables.rs:94:14:96:5 | BlockExpr | |
@@ -455,10 +457,11 @@ edges
455457
| variables.rs:224:13:224:27 | ExprStmt | variables.rs:224:13:224:21 | PathExpr | |
456458
| variables.rs:224:23:224:25 | a11 | variables.rs:224:13:224:26 | CallExpr | |
457459
| variables.rs:225:13:228:13 | IfExpr | variables.rs:223:12:229:9 | BlockExpr | |
458-
| variables.rs:225:16:226:15 | LetExpr | variables.rs:225:20:225:36 | TupleStructPat | |
460+
| variables.rs:225:16:226:15 | LetExpr | variables.rs:226:15:226:15 | e | |
459461
| variables.rs:225:20:225:36 | TupleStructPat | variables.rs:225:13:228:13 | IfExpr | no-match |
460462
| variables.rs:225:20:225:36 | TupleStructPat | variables.rs:225:33:225:35 | a12 | match |
461463
| variables.rs:225:33:225:35 | a12 | variables.rs:227:17:227:32 | ExprStmt | match |
464+
| variables.rs:226:15:226:15 | e | variables.rs:225:20:225:36 | TupleStructPat | |
462465
| variables.rs:226:17:228:13 | BlockExpr | variables.rs:225:13:228:13 | IfExpr | |
463466
| variables.rs:227:17:227:25 | PathExpr | variables.rs:227:28:227:30 | a12 | |
464467
| variables.rs:227:17:227:31 | CallExpr | variables.rs:226:17:228:13 | BlockExpr | |
@@ -674,7 +677,10 @@ edges
674677
| variables.rs:332:5:332:17 | ExprStmt | variables.rs:332:5:332:13 | PathExpr | |
675678
| variables.rs:332:15:332:15 | a | variables.rs:332:5:332:16 | CallExpr | |
676679
| variables.rs:333:5:333:27 | MethodCallExpr | variables.rs:334:5:334:17 | ExprStmt | |
677-
| variables.rs:333:5:333:28 | ExprStmt | variables.rs:333:5:333:27 | MethodCallExpr | |
680+
| variables.rs:333:5:333:28 | ExprStmt | variables.rs:333:25:333:26 | 10 | |
681+
| variables.rs:333:6:333:11 | RefExpr | variables.rs:333:5:333:27 | MethodCallExpr | |
682+
| variables.rs:333:11:333:11 | a | variables.rs:333:6:333:11 | RefExpr | |
683+
| variables.rs:333:25:333:26 | 10 | variables.rs:333:11:333:11 | a | |
678684
| variables.rs:334:5:334:13 | PathExpr | variables.rs:334:15:334:15 | a | |
679685
| variables.rs:334:5:334:16 | CallExpr | variables.rs:329:17:335:1 | BlockExpr | |
680686
| variables.rs:334:5:334:17 | ExprStmt | variables.rs:334:5:334:13 | PathExpr | |

0 commit comments

Comments
 (0)