Skip to content

Commit

Permalink
Rust: Handle early returns in async blocks in CFG
Browse files Browse the repository at this point in the history
  • Loading branch information
hvitved committed Nov 19, 2024
1 parent b6103e1 commit bb8d0b4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions rust/ql/lib/codeql/rust/controlflow/internal/Scope.qll
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ final class AsyncBlockScope extends CfgScopeImpl, AsyncBlockExpr instanceof Expr

override predicate scopeLast(AstNode last, Completion c) {
last(super.getLastChildElement(), last, c)
or
last(super.getChildNode(_), last, c) and
not c instanceof NormalCompletion
}
}

Expand Down
1 change: 1 addition & 0 deletions rust/ql/test/library-tests/controlflow/Cfg.expected
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,7 @@ edges
| test.rs:403:13:405:14 | ExprStmt | test.rs:403:16:403:16 | b | |
| test.rs:403:16:403:16 | b | test.rs:403:13:405:13 | IfExpr | false |
| test.rs:403:16:403:16 | b | test.rs:404:17:404:41 | ExprStmt | true |
| test.rs:404:17:404:40 | ReturnExpr | test.rs:402:28:407:9 | exit BlockExpr (normal) | return |
| test.rs:404:17:404:41 | ExprStmt | test.rs:404:24:404:34 | async_block | |
| test.rs:404:24:404:34 | async_block | test.rs:404:36:404:39 | true | |
| test.rs:404:24:404:40 | CallExpr | test.rs:404:17:404:40 | ReturnExpr | |
Expand Down

0 comments on commit bb8d0b4

Please sign in to comment.