Skip to content

Commit

Permalink
Rust: Fix bugs in LetExprTree and MethodCallExprTree
Browse files Browse the repository at this point in the history
  • Loading branch information
hvitved committed Oct 10, 2024
1 parent 699e6ec commit 9ed1394
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,14 @@ class ItemTree extends LeafTree, Item { }
// `LetExpr` is a pre-order tree such that the pattern itself ends up
// dominating successors in the graph in the same way that patterns do in
// `match` expressions.
class LetExprTree extends StandardPreOrderTree instanceof LetExpr {
override AstNode getChildNode(int i) { i = 0 and result = super.getPat() }
class LetExprTree extends StandardPreOrderTree, LetExpr {
override AstNode getChildNode(int i) {
i = 0 and
result = this.getExpr()
or
i = 1 and
result = this.getPat()
}
}

class LetStmtTree extends PreOrderTree, LetStmt {
Expand Down Expand Up @@ -479,10 +485,12 @@ class MatchExprTree extends PostOrderTree instanceof MatchExpr {
}
}

class MethodCallExprTree extends StandardPostOrderTree instanceof MethodCallExpr {
class MethodCallExprTree extends StandardPostOrderTree, MethodCallExpr {
override AstNode getChildNode(int i) {
result = super.getReceiver() and
result = super.getArgList().getArg(i + 1)
i = 0 and
result = this.getReceiver()
or
result = this.getArgList().getArg(i + 1)
}
}

Expand Down
10 changes: 7 additions & 3 deletions rust/ql/test/library-tests/controlflow/Cfg.expected
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,12 @@ edges
| test.rs:80:24:80:28 | RangeExpr | test.rs:80:13:80:20 | iter | |
| test.rs:80:27:80:28 | 10 | test.rs:80:24:80:28 | RangeExpr | |
| test.rs:81:9:85:9 | WhileExpr | test.rs:79:25:86:5 | BlockExpr | |
| test.rs:81:15:81:39 | LetExpr | test.rs:81:19:81:25 | TupleStructPat | |
| test.rs:81:15:81:39 | LetExpr | test.rs:81:29:81:32 | iter | |
| test.rs:81:19:81:25 | TupleStructPat | test.rs:81:9:85:9 | WhileExpr | no-match |
| test.rs:81:19:81:25 | TupleStructPat | test.rs:81:24:81:24 | x | match |
| test.rs:81:24:81:24 | x | test.rs:82:17:82:17 | PathExpr | match |
| test.rs:81:29:81:32 | iter | test.rs:81:29:81:39 | MethodCallExpr | |
| test.rs:81:29:81:39 | MethodCallExpr | test.rs:81:19:81:25 | TupleStructPat | |
| test.rs:81:41:85:9 | BlockExpr | test.rs:81:15:81:39 | LetExpr | |
| test.rs:82:13:84:13 | IfExpr | test.rs:81:41:85:9 | BlockExpr | |
| test.rs:82:17:82:17 | PathExpr | test.rs:82:21:82:21 | 5 | |
Expand Down Expand Up @@ -233,10 +235,11 @@ edges
| test.rs:113:25:113:38 | Param | test.rs:114:12:114:26 | LetExpr | |
| test.rs:113:48:119:5 | BlockExpr | test.rs:113:5:119:5 | exit test_if_let_else (normal) | |
| test.rs:114:9:118:9 | IfExpr | test.rs:113:48:119:5 | BlockExpr | |
| test.rs:114:12:114:26 | LetExpr | test.rs:114:16:114:22 | TupleStructPat | |
| test.rs:114:12:114:26 | LetExpr | test.rs:114:26:114:26 | a | |
| test.rs:114:16:114:22 | TupleStructPat | test.rs:114:21:114:21 | n | match |
| test.rs:114:16:114:22 | TupleStructPat | test.rs:117:13:117:13 | 0 | no-match |
| test.rs:114:21:114:21 | n | test.rs:115:13:115:13 | n | match |
| test.rs:114:26:114:26 | a | test.rs:114:16:114:22 | TupleStructPat | |
| test.rs:114:28:116:9 | BlockExpr | test.rs:114:9:118:9 | IfExpr | |
| test.rs:115:13:115:13 | n | test.rs:114:28:116:9 | BlockExpr | |
| test.rs:116:16:118:9 | BlockExpr | test.rs:114:9:118:9 | IfExpr | |
Expand All @@ -248,10 +251,11 @@ edges
| test.rs:121:43:126:5 | BlockExpr | test.rs:121:5:126:5 | exit test_if_let (normal) | |
| test.rs:122:9:124:9 | ExprStmt | test.rs:122:12:122:26 | LetExpr | |
| test.rs:122:9:124:9 | IfExpr | test.rs:125:9:125:9 | 0 | |
| test.rs:122:12:122:26 | LetExpr | test.rs:122:16:122:22 | TupleStructPat | |
| test.rs:122:12:122:26 | LetExpr | test.rs:122:26:122:26 | a | |
| test.rs:122:16:122:22 | TupleStructPat | test.rs:122:9:124:9 | IfExpr | no-match |
| test.rs:122:16:122:22 | TupleStructPat | test.rs:122:21:122:21 | n | match |
| test.rs:122:21:122:21 | n | test.rs:123:13:123:13 | n | match |
| test.rs:122:26:122:26 | a | test.rs:122:16:122:22 | TupleStructPat | |
| test.rs:122:28:124:9 | BlockExpr | test.rs:122:9:124:9 | IfExpr | |
| test.rs:123:13:123:13 | n | test.rs:122:28:124:9 | BlockExpr | |
| test.rs:125:9:125:9 | 0 | test.rs:121:43:126:5 | BlockExpr | |
Expand Down
14 changes: 10 additions & 4 deletions rust/ql/test/library-tests/variables/Cfg.expected
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,11 @@ edges
| variables.rs:74:19:74:40 | CallExpr | variables.rs:74:14:74:41 | CallExpr | |
| variables.rs:74:32:74:39 | "Hello!" | variables.rs:74:19:74:40 | CallExpr | |
| variables.rs:76:5:79:5 | IfExpr | variables.rs:73:19:80:1 | BlockExpr | |
| variables.rs:76:8:77:12 | LetExpr | variables.rs:76:12:76:23 | TupleStructPat | |
| variables.rs:76:8:77:12 | LetExpr | variables.rs:77:11:77:12 | s1 | |
| variables.rs:76:12:76:23 | TupleStructPat | variables.rs:76:5:79:5 | IfExpr | no-match |
| variables.rs:76:12:76:23 | TupleStructPat | variables.rs:76:17:76:22 | s2 | match |
| variables.rs:76:17:76:22 | s2 | variables.rs:78:9:78:22 | ExprStmt | match |
| variables.rs:77:11:77:12 | s1 | variables.rs:76:12:76:23 | TupleStructPat | |
| variables.rs:77:14:79:5 | BlockExpr | variables.rs:76:5:79:5 | IfExpr | |
| variables.rs:78:9:78:17 | PathExpr | variables.rs:78:19:78:20 | s2 | |
| variables.rs:78:9:78:21 | CallExpr | variables.rs:77:14:79:5 | BlockExpr | |
Expand Down Expand Up @@ -184,10 +185,11 @@ edges
| variables.rs:91:19:91:40 | CallExpr | variables.rs:91:14:91:41 | CallExpr | |
| variables.rs:91:32:91:39 | "Hello!" | variables.rs:91:19:91:40 | CallExpr | |
| variables.rs:93:5:96:5 | WhileExpr | variables.rs:90:19:97:1 | BlockExpr | |
| variables.rs:93:11:94:12 | LetExpr | variables.rs:93:15:93:26 | TupleStructPat | |
| variables.rs:93:11:94:12 | LetExpr | variables.rs:94:11:94:12 | s1 | |
| variables.rs:93:15:93:26 | TupleStructPat | variables.rs:93:5:96:5 | WhileExpr | no-match |
| variables.rs:93:15:93:26 | TupleStructPat | variables.rs:93:20:93:25 | s2 | match |
| variables.rs:93:20:93:25 | s2 | variables.rs:95:9:95:22 | ExprStmt | match |
| variables.rs:94:11:94:12 | s1 | variables.rs:93:15:93:26 | TupleStructPat | |
| variables.rs:94:14:96:5 | BlockExpr | variables.rs:93:11:94:12 | LetExpr | |
| variables.rs:95:9:95:17 | PathExpr | variables.rs:95:19:95:20 | s2 | |
| variables.rs:95:9:95:21 | CallExpr | variables.rs:94:14:96:5 | BlockExpr | |
Expand Down Expand Up @@ -455,10 +457,11 @@ edges
| variables.rs:224:13:224:27 | ExprStmt | variables.rs:224:13:224:21 | PathExpr | |
| variables.rs:224:23:224:25 | a11 | variables.rs:224:13:224:26 | CallExpr | |
| variables.rs:225:13:228:13 | IfExpr | variables.rs:223:12:229:9 | BlockExpr | |
| variables.rs:225:16:226:15 | LetExpr | variables.rs:225:20:225:36 | TupleStructPat | |
| variables.rs:225:16:226:15 | LetExpr | variables.rs:226:15:226:15 | e | |
| variables.rs:225:20:225:36 | TupleStructPat | variables.rs:225:13:228:13 | IfExpr | no-match |
| variables.rs:225:20:225:36 | TupleStructPat | variables.rs:225:33:225:35 | a12 | match |
| variables.rs:225:33:225:35 | a12 | variables.rs:227:17:227:32 | ExprStmt | match |
| variables.rs:226:15:226:15 | e | variables.rs:225:20:225:36 | TupleStructPat | |
| variables.rs:226:17:228:13 | BlockExpr | variables.rs:225:13:228:13 | IfExpr | |
| variables.rs:227:17:227:25 | PathExpr | variables.rs:227:28:227:30 | a12 | |
| variables.rs:227:17:227:31 | CallExpr | variables.rs:226:17:228:13 | BlockExpr | |
Expand Down Expand Up @@ -674,7 +677,10 @@ edges
| variables.rs:332:5:332:17 | ExprStmt | variables.rs:332:5:332:13 | PathExpr | |
| variables.rs:332:15:332:15 | a | variables.rs:332:5:332:16 | CallExpr | |
| variables.rs:333:5:333:27 | MethodCallExpr | variables.rs:334:5:334:17 | ExprStmt | |
| variables.rs:333:5:333:28 | ExprStmt | variables.rs:333:5:333:27 | MethodCallExpr | |
| variables.rs:333:5:333:28 | ExprStmt | variables.rs:333:25:333:26 | 10 | |
| variables.rs:333:6:333:11 | RefExpr | variables.rs:333:5:333:27 | MethodCallExpr | |
| variables.rs:333:11:333:11 | a | variables.rs:333:6:333:11 | RefExpr | |
| variables.rs:333:25:333:26 | 10 | variables.rs:333:11:333:11 | a | |
| variables.rs:334:5:334:13 | PathExpr | variables.rs:334:15:334:15 | a | |
| variables.rs:334:5:334:16 | CallExpr | variables.rs:329:17:335:1 | BlockExpr | |
| variables.rs:334:5:334:17 | ExprStmt | variables.rs:334:5:334:13 | PathExpr | |
Expand Down

0 comments on commit 9ed1394

Please sign in to comment.