Skip to content

Commit 9c172f6

Browse files
committed
Rust: Fix dead end in CFG for match expressions with no arms
1 parent 381f061 commit 9c172f6

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,9 +494,13 @@ class MatchExprTree extends PostOrderTree instanceof MatchExpr {
494494
override predicate first(AstNode node) { first(super.getExpr(), node) }
495495

496496
override predicate succ(AstNode pred, AstNode succ, Completion c) {
497-
// Edge from the scrutinee to the first arm.
497+
// Edge from the scrutinee to the first arm or to the match expression if no arms.
498498
last(super.getExpr(), pred, c) and
499-
first(super.getArm(0).getPat(), succ) and
499+
(
500+
first(super.getArm(0).getPat(), succ)
501+
or
502+
not exists(super.getArm(0)) and succ = this
503+
) and
500504
completionIsNormal(c)
501505
or
502506
// Edge from a failed pattern or guard in one arm to the beginning of the next arm.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,8 @@ edges
681681
| test.rs:311:26:311:30 | value | test.rs:310:9:313:9 | MatchExpr | |
682682
| test.rs:312:13:312:22 | TupleStructPat | test.rs:312:17:312:21 | never | match |
683683
| test.rs:312:17:312:21 | never | test.rs:312:33:312:37 | never | match |
684+
| test.rs:312:27:312:40 | MatchExpr | test.rs:310:9:313:9 | MatchExpr | |
685+
| test.rs:312:33:312:37 | never | test.rs:312:27:312:40 | MatchExpr | |
684686
| test.rs:319:5:322:5 | enter test_let_match | test.rs:319:23:319:23 | a | |
685687
| test.rs:319:5:322:5 | exit test_let_match (normal) | test.rs:319:5:322:5 | exit test_let_match | |
686688
| test.rs:319:23:319:23 | a | test.rs:319:23:319:36 | Param | match |

0 commit comments

Comments
 (0)