Skip to content

Commit bb8d0b4

Browse files
committed
Rust: Handle early returns in async blocks in CFG
1 parent b6103e1 commit bb8d0b4

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ final class AsyncBlockScope extends CfgScopeImpl, AsyncBlockExpr instanceof Expr
2222

2323
override predicate scopeLast(AstNode last, Completion c) {
2424
last(super.getLastChildElement(), last, c)
25+
or
26+
last(super.getChildNode(_), last, c) and
27+
not c instanceof NormalCompletion
2528
}
2629
}
2730

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,7 @@ edges
892892
| test.rs:403:13:405:14 | ExprStmt | test.rs:403:16:403:16 | b | |
893893
| test.rs:403:16:403:16 | b | test.rs:403:13:405:13 | IfExpr | false |
894894
| test.rs:403:16:403:16 | b | test.rs:404:17:404:41 | ExprStmt | true |
895+
| test.rs:404:17:404:40 | ReturnExpr | test.rs:402:28:407:9 | exit BlockExpr (normal) | return |
895896
| test.rs:404:17:404:41 | ExprStmt | test.rs:404:24:404:34 | async_block | |
896897
| test.rs:404:24:404:34 | async_block | test.rs:404:36:404:39 | true | |
897898
| test.rs:404:24:404:40 | CallExpr | test.rs:404:17:404:40 | ReturnExpr | |

0 commit comments

Comments
 (0)