Skip to content

Commit 24adbb8

Browse files
committed
Rust: Include self parameters in the CFG
1 parent 55121d8 commit 24adbb8

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,17 @@ import CfgImpl
7272
class CallableScopeTree extends StandardTree, PreOrderTree, PostOrderTree, Scope::CallableScope {
7373
override predicate propagatesAbnormal(AstNode child) { none() }
7474

75+
private int getNumberOfSelfParams() {
76+
if this.getParamList().hasSelfParam() then result = 1 else result = 0
77+
}
78+
7579
override AstNode getChildNode(int i) {
76-
result = this.getParamList().getParam(i)
80+
i = 0 and
81+
result = this.getParamList().getSelfParam()
82+
or
83+
result = this.getParamList().getParam(i - this.getNumberOfSelfParams())
7784
or
78-
i = this.getParamList().getNumberOfParams() and
85+
i = this.getParamList().getNumberOfParams() + this.getNumberOfSelfParams() and
7986
result = this.getBody()
8087
}
8188
}
@@ -191,6 +198,10 @@ class NameTree extends LeafTree, Name { }
191198

192199
class NameRefTree extends LeafTree, NameRef { }
193200

201+
class SelfParamTree extends StandardPostOrderTree, SelfParam {
202+
override AstNode getChildNode(int i) { i = 0 and result = this.getName() }
203+
}
204+
194205
class TypeRefTree extends LeafTree instanceof TypeRef { }
195206

196207
/**

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,14 +1051,18 @@ edges
10511051
| test.rs:502:28:504:5 | BlockExpr | test.rs:502:5:504:5 | exit new (normal) | |
10521052
| test.rs:503:9:503:25 | RecordExpr | test.rs:502:28:504:5 | BlockExpr | |
10531053
| test.rs:503:23:503:23 | a | test.rs:503:9:503:25 | RecordExpr | |
1054-
| test.rs:506:5:508:5 | enter negated | test.rs:507:23:507:26 | self | |
1054+
| test.rs:506:5:508:5 | enter negated | test.rs:506:16:506:19 | self | |
10551055
| test.rs:506:5:508:5 | exit negated (normal) | test.rs:506:5:508:5 | exit negated | |
1056+
| test.rs:506:16:506:19 | SelfParam | test.rs:507:23:507:26 | self | |
1057+
| test.rs:506:16:506:19 | self | test.rs:506:16:506:19 | SelfParam | |
10561058
| test.rs:506:30:508:5 | BlockExpr | test.rs:506:5:508:5 | exit negated (normal) | |
10571059
| test.rs:507:9:507:30 | RecordExpr | test.rs:506:30:508:5 | BlockExpr | |
10581060
| test.rs:507:23:507:26 | self | test.rs:507:23:507:28 | FieldExpr | |
10591061
| test.rs:507:23:507:28 | FieldExpr | test.rs:507:9:507:30 | RecordExpr | |
1060-
| test.rs:510:5:512:5 | enter multifly_add | test.rs:510:32:510:32 | a | |
1062+
| test.rs:510:5:512:5 | enter multifly_add | test.rs:510:26:510:29 | self | |
10611063
| test.rs:510:5:512:5 | exit multifly_add (normal) | test.rs:510:5:512:5 | exit multifly_add | |
1064+
| test.rs:510:21:510:29 | SelfParam | test.rs:510:32:510:32 | a | |
1065+
| test.rs:510:26:510:29 | self | test.rs:510:21:510:29 | SelfParam | |
10621066
| test.rs:510:32:510:32 | a | test.rs:510:32:510:37 | Param | match |
10631067
| test.rs:510:32:510:37 | Param | test.rs:510:40:510:40 | b | |
10641068
| test.rs:510:40:510:40 | b | test.rs:510:40:510:45 | Param | match |

0 commit comments

Comments
 (0)