Skip to content

Commit 811bdf2

Browse files
committed
Rust: Implement cfg for CfgPredExpr and CfgPredPat
1 parent 53e1289 commit 811bdf2

5 files changed

Lines changed: 57 additions & 1 deletion

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ module ExprTrees {
380380

381381
class LiteralExprTree extends LeafTree instanceof LiteralExpr { }
382382

383+
class CfgPredExprTree extends LeafTree instanceof CfgPredExpr { }
384+
383385
abstract class LoopingExprTree extends PostOrderTree {
384386
override predicate propagatesAbnormal(AstNode child) { child = this.getLoopBody() }
385387

@@ -630,6 +632,8 @@ module PatternTrees {
630632

631633
class RestPatTree extends LeafTree, RestPat { }
632634

635+
class CfgPredPatTree extends LeafTree, CfgPredPat { }
636+
633637
class LiteralPatTree extends StandardPostOrderTree, LiteralPat {
634638
override AstNode getChildNode(int i) { i = 0 and result = this.getLiteral() }
635639
}

‎rust/ql/test/library-tests/controlflow/BasicBlocks.expected‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
dominates
2+
| cfg.rs:1:1:3:1 | enter fn cfg_expr | cfg.rs:1:1:3:1 | enter fn cfg_expr |
3+
| cfg.rs:5:1:10:1 | enter fn cfg_pat | cfg.rs:5:1:10:1 | enter fn cfg_pat |
4+
| cfg.rs:5:1:10:1 | enter fn cfg_pat | cfg.rs:6:5:9:5 | match value { ... } |
5+
| cfg.rs:5:1:10:1 | enter fn cfg_pat | cfg.rs:7:23:7:26 | true |
6+
| cfg.rs:5:1:10:1 | enter fn cfg_pat | cfg.rs:8:9:8:9 | _ |
7+
| cfg.rs:6:5:9:5 | match value { ... } | cfg.rs:6:5:9:5 | match value { ... } |
8+
| cfg.rs:7:23:7:26 | true | cfg.rs:7:23:7:26 | true |
9+
| cfg.rs:8:9:8:9 | _ | cfg.rs:8:9:8:9 | _ |
210
| test.rs:5:5:8:5 | enter fn function_call | test.rs:5:5:8:5 | enter fn function_call |
311
| test.rs:10:5:13:5 | enter fn method_call | test.rs:10:5:13:5 | enter fn method_call |
412
| test.rs:18:5:24:5 | enter fn next | test.rs:18:5:24:5 | enter fn next |
@@ -783,6 +791,14 @@ dominates
783791
| test.rs:615:5:617:5 | enter fn negated | test.rs:615:5:617:5 | enter fn negated |
784792
| test.rs:619:5:621:5 | enter fn multifly_add | test.rs:619:5:621:5 | enter fn multifly_add |
785793
postDominance
794+
| cfg.rs:1:1:3:1 | enter fn cfg_expr | cfg.rs:1:1:3:1 | enter fn cfg_expr |
795+
| cfg.rs:5:1:10:1 | enter fn cfg_pat | cfg.rs:5:1:10:1 | enter fn cfg_pat |
796+
| cfg.rs:6:5:9:5 | match value { ... } | cfg.rs:5:1:10:1 | enter fn cfg_pat |
797+
| cfg.rs:6:5:9:5 | match value { ... } | cfg.rs:6:5:9:5 | match value { ... } |
798+
| cfg.rs:6:5:9:5 | match value { ... } | cfg.rs:7:23:7:26 | true |
799+
| cfg.rs:6:5:9:5 | match value { ... } | cfg.rs:8:9:8:9 | _ |
800+
| cfg.rs:7:23:7:26 | true | cfg.rs:7:23:7:26 | true |
801+
| cfg.rs:8:9:8:9 | _ | cfg.rs:8:9:8:9 | _ |
786802
| test.rs:5:5:8:5 | enter fn function_call | test.rs:5:5:8:5 | enter fn function_call |
787803
| test.rs:10:5:13:5 | enter fn method_call | test.rs:10:5:13:5 | enter fn method_call |
788804
| test.rs:18:5:24:5 | enter fn next | test.rs:18:5:24:5 | enter fn next |
@@ -1463,6 +1479,9 @@ postDominance
14631479
| test.rs:615:5:617:5 | enter fn negated | test.rs:615:5:617:5 | enter fn negated |
14641480
| test.rs:619:5:621:5 | enter fn multifly_add | test.rs:619:5:621:5 | enter fn multifly_add |
14651481
immediateDominator
1482+
| cfg.rs:6:5:9:5 | match value { ... } | cfg.rs:5:1:10:1 | enter fn cfg_pat |
1483+
| cfg.rs:7:23:7:26 | true | cfg.rs:5:1:10:1 | enter fn cfg_pat |
1484+
| cfg.rs:8:9:8:9 | _ | cfg.rs:5:1:10:1 | enter fn cfg_pat |
14661485
| test.rs:19:9:23:9 | if ... {...} else {...} | test.rs:18:5:24:5 | enter fn next |
14671486
| test.rs:20:13:20:13 | n | test.rs:18:5:24:5 | enter fn next |
14681487
| test.rs:22:13:22:13 | 3 | test.rs:18:5:24:5 | enter fn next |
@@ -2087,6 +2106,8 @@ successor
20872106
| test.rs:571:9:573:9 | if ... {...} | test.rs:575:9:577:9 | if ... {...} | false |
20882107
| test.rs:571:9:573:9 | if ... {...} | test.rs:576:13:576:27 | ExprStmt | true |
20892108
joinBlockPredecessor
2109+
| cfg.rs:6:5:9:5 | match value { ... } | cfg.rs:7:23:7:26 | true | 0 |
2110+
| cfg.rs:6:5:9:5 | match value { ... } | cfg.rs:8:9:8:9 | _ | 1 |
20902111
| test.rs:19:9:23:9 | if ... {...} else {...} | test.rs:20:13:20:13 | n | 1 |
20912112
| test.rs:19:9:23:9 | if ... {...} else {...} | test.rs:22:13:22:13 | 3 | 0 |
20922113
| test.rs:26:5:42:5 | exit fn test_break_and_continue (normal) | test.rs:31:17:31:29 | ExprStmt | 0 |

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
11
edges
2+
| cfg.rs:1:1:3:1 | enter fn cfg_expr | cfg.rs:2:9:2:14 | CfgPredExpr | |
3+
| cfg.rs:1:1:3:1 | exit fn cfg_expr (normal) | cfg.rs:1:1:3:1 | exit fn cfg_expr | |
4+
| cfg.rs:1:27:3:1 | { ... } | cfg.rs:1:1:3:1 | exit fn cfg_expr (normal) | |
5+
| cfg.rs:2:5:2:14 | MacroExpr | cfg.rs:1:27:3:1 | { ... } | |
6+
| cfg.rs:2:5:2:14 | cfg!... | cfg.rs:2:5:2:14 | MacroExpr | |
7+
| cfg.rs:2:9:2:14 | CfgPredExpr | cfg.rs:2:9:2:14 | { ... } | |
8+
| cfg.rs:2:9:2:14 | { ... } | cfg.rs:2:5:2:14 | cfg!... | |
9+
| cfg.rs:5:1:10:1 | enter fn cfg_pat | cfg.rs:5:16:5:20 | value | |
10+
| cfg.rs:5:1:10:1 | exit fn cfg_pat (normal) | cfg.rs:5:1:10:1 | exit fn cfg_pat | |
11+
| cfg.rs:5:16:5:20 | value | cfg.rs:5:16:5:20 | value | |
12+
| cfg.rs:5:16:5:20 | value | cfg.rs:5:16:5:26 | ...: bool | match |
13+
| cfg.rs:5:16:5:26 | ...: bool | cfg.rs:6:11:6:15 | value | |
14+
| cfg.rs:5:37:10:1 | { ... } | cfg.rs:5:1:10:1 | exit fn cfg_pat (normal) | |
15+
| cfg.rs:6:5:9:5 | match value { ... } | cfg.rs:5:37:10:1 | { ... } | |
16+
| cfg.rs:6:11:6:15 | value | cfg.rs:7:9:7:18 | MacroPat | |
17+
| cfg.rs:7:9:7:18 | MacroPat | cfg.rs:7:13:7:18 | CfgPredPat | match |
18+
| cfg.rs:7:13:7:18 | CfgPredPat | cfg.rs:7:23:7:26 | true | match |
19+
| cfg.rs:7:13:7:18 | CfgPredPat | cfg.rs:8:9:8:9 | _ | no-match |
20+
| cfg.rs:7:23:7:26 | true | cfg.rs:6:5:9:5 | match value { ... } | |
21+
| cfg.rs:8:9:8:9 | _ | cfg.rs:8:14:8:18 | false | match |
22+
| cfg.rs:8:14:8:18 | false | cfg.rs:6:5:9:5 | match value { ... } | |
223
| test.rs:5:5:8:5 | enter fn function_call | test.rs:6:9:6:64 | ExprStmt | |
324
| test.rs:5:5:8:5 | exit fn function_call (normal) | test.rs:5:5:8:5 | exit fn function_call | |
425
| test.rs:5:24:8:5 | { ... } | test.rs:5:5:8:5 | exit fn function_call (normal) | |
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
pub fn cfg_expr() -> bool {
2+
cfg!(unix)
3+
}
4+
5+
pub fn cfg_pat(value: bool) -> bool {
6+
match value {
7+
cfg!(unix) => true,
8+
_ => false,
9+
}
10+
}

‎rust/ql/test/library-tests/type-inference/type-inference.expected‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11597,8 +11597,8 @@ inferType
1159711597
| main.rs:2295:19:2295:26 | strings1 | TArray.TRef | {EXTERNAL LOCATION} | str |
1159811598
| main.rs:2295:28:2295:29 | { ... } | | {EXTERNAL LOCATION} | () |
1159911599
| main.rs:2296:9:2296:33 | for ... in ... { ... } | | {EXTERNAL LOCATION} | () |
11600-
| main.rs:2296:13:2296:13 | s | | {EXTERNAL LOCATION} | &mut |
1160111600
| main.rs:2296:13:2296:13 | s | | {EXTERNAL LOCATION} | I::Item[Iterator] |
11601+
| main.rs:2296:13:2296:13 | s | | {EXTERNAL LOCATION} | &mut |
1160211602
| main.rs:2296:13:2296:13 | s | TRefMut | {EXTERNAL LOCATION} | & |
1160311603
| main.rs:2296:13:2296:13 | s | TRefMut.TRef | {EXTERNAL LOCATION} | str |
1160411604
| main.rs:2296:18:2296:30 | &mut strings1 | | {EXTERNAL LOCATION} | &mut |

0 commit comments

Comments
 (0)