Skip to content

Commit

Permalink
Rust: Improve CFG for let expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
hvitved committed Nov 18, 2024
1 parent 3eaf1e5 commit 5478237
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
8 changes: 7 additions & 1 deletion rust/ql/lib/codeql/rust/controlflow/internal/Splitting.qll
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ module ConditionalCompletionSplitting {
child = parent.(LogicalNotExpr).getExpr() and
childCompletion.getDual() = parentCompletion
or
childCompletion = parentCompletion and
(
childCompletion = parentCompletion
or
// needed for `let` expressions
childCompletion.(MatchCompletion).getValue() =
parentCompletion.(BooleanCompletion).getValue()
) and
(
child = parent.(BinaryLogicalOperation).getAnOperand()
or
Expand Down
12 changes: 5 additions & 7 deletions rust/ql/test/library-tests/controlflow/Cfg.expected
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,12 @@ edges
| test.rs:145:9:149:9 | IfExpr | test.rs:144:67:150:5 | BlockExpr | |
| test.rs:145:12:145:12 | a | test.rs:145:12:145:31 | [boolean(false)] ... && ... | false |
| test.rs:145:12:145:12 | a | test.rs:145:17:145:31 | LetExpr | true |
| test.rs:145:12:145:31 | ... && ... | test.rs:146:13:146:13 | d | true |
| test.rs:145:12:145:31 | ... && ... | test.rs:148:13:148:17 | false | false |
| test.rs:145:12:145:31 | [boolean(false)] ... && ... | test.rs:148:13:148:17 | false | false |
| test.rs:145:12:145:31 | [boolean(true)] ... && ... | test.rs:146:13:146:13 | d | true |
| test.rs:145:17:145:31 | LetExpr | test.rs:145:31:145:31 | b | |
| test.rs:145:21:145:27 | TupleStructPat | test.rs:145:12:145:31 | ... && ... | no-match |
| test.rs:145:21:145:27 | TupleStructPat | test.rs:145:12:145:31 | [boolean(false)] ... && ... | no-match |
| test.rs:145:21:145:27 | TupleStructPat | test.rs:145:26:145:26 | d | match |
| test.rs:145:26:145:26 | d | test.rs:145:12:145:31 | ... && ... | match |
| test.rs:145:26:145:26 | d | test.rs:145:12:145:31 | [boolean(true)] ... && ... | match |
| test.rs:145:31:145:31 | b | test.rs:145:21:145:27 | TupleStructPat | |
| test.rs:145:33:147:9 | BlockExpr | test.rs:145:9:149:9 | IfExpr | |
| test.rs:146:13:146:13 | d | test.rs:145:33:147:9 | BlockExpr | |
Expand All @@ -312,13 +311,12 @@ edges
| test.rs:153:9:157:9 | IfExpr | test.rs:152:59:158:5 | BlockExpr | |
| test.rs:153:12:153:12 | a | test.rs:153:12:153:25 | [boolean(false)] ... && ... | false |
| test.rs:153:12:153:12 | a | test.rs:153:17:153:25 | LetExpr | true |
| test.rs:153:12:153:25 | ... && ... | test.rs:153:12:153:30 | [boolean(false)] ... && ... | false |
| test.rs:153:12:153:25 | ... && ... | test.rs:153:30:153:30 | c | true |
| test.rs:153:12:153:25 | [boolean(false)] ... && ... | test.rs:153:12:153:30 | [boolean(false)] ... && ... | false |
| test.rs:153:12:153:25 | [boolean(true)] ... && ... | test.rs:153:30:153:30 | c | true |
| test.rs:153:12:153:30 | [boolean(false)] ... && ... | test.rs:156:13:156:17 | false | false |
| test.rs:153:12:153:30 | [boolean(true)] ... && ... | test.rs:154:13:154:13 | d | true |
| test.rs:153:17:153:25 | LetExpr | test.rs:153:25:153:25 | b | |
| test.rs:153:21:153:21 | d | test.rs:153:12:153:25 | ... && ... | match |
| test.rs:153:21:153:21 | d | test.rs:153:12:153:25 | [boolean(true)] ... && ... | match |
| test.rs:153:25:153:25 | b | test.rs:153:21:153:21 | d | |
| test.rs:153:30:153:30 | c | test.rs:153:12:153:30 | [boolean(false)] ... && ... | false |
| test.rs:153:30:153:30 | c | test.rs:153:12:153:30 | [boolean(true)] ... && ... | true |
Expand Down

0 comments on commit 5478237

Please sign in to comment.