Skip to content

Commit 5478237

Browse files
committed
Rust: Improve CFG for let expressions
1 parent 3eaf1e5 commit 5478237

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

Diff for: rust/ql/lib/codeql/rust/controlflow/internal/Splitting.qll

+7-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,13 @@ module ConditionalCompletionSplitting {
7171
child = parent.(LogicalNotExpr).getExpr() and
7272
childCompletion.getDual() = parentCompletion
7373
or
74-
childCompletion = parentCompletion and
74+
(
75+
childCompletion = parentCompletion
76+
or
77+
// needed for `let` expressions
78+
childCompletion.(MatchCompletion).getValue() =
79+
parentCompletion.(BooleanCompletion).getValue()
80+
) and
7581
(
7682
child = parent.(BinaryLogicalOperation).getAnOperand()
7783
or

Diff for: rust/ql/test/library-tests/controlflow/Cfg.expected

+5-7
Original file line numberDiff line numberDiff line change
@@ -288,13 +288,12 @@ edges
288288
| test.rs:145:9:149:9 | IfExpr | test.rs:144:67:150:5 | BlockExpr | |
289289
| test.rs:145:12:145:12 | a | test.rs:145:12:145:31 | [boolean(false)] ... && ... | false |
290290
| test.rs:145:12:145:12 | a | test.rs:145:17:145:31 | LetExpr | true |
291-
| test.rs:145:12:145:31 | ... && ... | test.rs:146:13:146:13 | d | true |
292-
| test.rs:145:12:145:31 | ... && ... | test.rs:148:13:148:17 | false | false |
293291
| test.rs:145:12:145:31 | [boolean(false)] ... && ... | test.rs:148:13:148:17 | false | false |
292+
| test.rs:145:12:145:31 | [boolean(true)] ... && ... | test.rs:146:13:146:13 | d | true |
294293
| test.rs:145:17:145:31 | LetExpr | test.rs:145:31:145:31 | b | |
295-
| test.rs:145:21:145:27 | TupleStructPat | test.rs:145:12:145:31 | ... && ... | no-match |
294+
| test.rs:145:21:145:27 | TupleStructPat | test.rs:145:12:145:31 | [boolean(false)] ... && ... | no-match |
296295
| test.rs:145:21:145:27 | TupleStructPat | test.rs:145:26:145:26 | d | match |
297-
| test.rs:145:26:145:26 | d | test.rs:145:12:145:31 | ... && ... | match |
296+
| test.rs:145:26:145:26 | d | test.rs:145:12:145:31 | [boolean(true)] ... && ... | match |
298297
| test.rs:145:31:145:31 | b | test.rs:145:21:145:27 | TupleStructPat | |
299298
| test.rs:145:33:147:9 | BlockExpr | test.rs:145:9:149:9 | IfExpr | |
300299
| test.rs:146:13:146:13 | d | test.rs:145:33:147:9 | BlockExpr | |
@@ -312,13 +311,12 @@ edges
312311
| test.rs:153:9:157:9 | IfExpr | test.rs:152:59:158:5 | BlockExpr | |
313312
| test.rs:153:12:153:12 | a | test.rs:153:12:153:25 | [boolean(false)] ... && ... | false |
314313
| test.rs:153:12:153:12 | a | test.rs:153:17:153:25 | LetExpr | true |
315-
| test.rs:153:12:153:25 | ... && ... | test.rs:153:12:153:30 | [boolean(false)] ... && ... | false |
316-
| test.rs:153:12:153:25 | ... && ... | test.rs:153:30:153:30 | c | true |
317314
| test.rs:153:12:153:25 | [boolean(false)] ... && ... | test.rs:153:12:153:30 | [boolean(false)] ... && ... | false |
315+
| test.rs:153:12:153:25 | [boolean(true)] ... && ... | test.rs:153:30:153:30 | c | true |
318316
| test.rs:153:12:153:30 | [boolean(false)] ... && ... | test.rs:156:13:156:17 | false | false |
319317
| test.rs:153:12:153:30 | [boolean(true)] ... && ... | test.rs:154:13:154:13 | d | true |
320318
| test.rs:153:17:153:25 | LetExpr | test.rs:153:25:153:25 | b | |
321-
| test.rs:153:21:153:21 | d | test.rs:153:12:153:25 | ... && ... | match |
319+
| test.rs:153:21:153:21 | d | test.rs:153:12:153:25 | [boolean(true)] ... && ... | match |
322320
| test.rs:153:25:153:25 | b | test.rs:153:21:153:21 | d | |
323321
| test.rs:153:30:153:30 | c | test.rs:153:12:153:30 | [boolean(false)] ... && ... | false |
324322
| test.rs:153:30:153:30 | c | test.rs:153:12:153:30 | [boolean(true)] ... && ... | true |

0 commit comments

Comments
 (0)