|
| 1 | +/** |
| 2 | + * Provides classes for recognizing control flow graph inconsistencies. |
| 3 | + */ |
| 4 | + |
| 5 | +private import rust |
| 6 | +private import codeql.rust.controlflow.internal.ControlFlowGraphImpl::Consistency as Consistency |
| 7 | +import Consistency |
| 8 | +private import codeql.rust.controlflow.ControlFlowGraph |
| 9 | +private import codeql.rust.controlflow.internal.ControlFlowGraphImpl as CfgImpl |
| 10 | +private import codeql.rust.controlflow.internal.Completion |
| 11 | + |
| 12 | +/** |
| 13 | + * All `Expr` nodes are `PostOrderTree`s |
| 14 | + */ |
| 15 | +query predicate nonPostOrderExpr(Expr e, string cls) { |
| 16 | + cls = e.getPrimaryQlClasses() and |
| 17 | + not e instanceof LetExpr and |
| 18 | + not e instanceof ParenExpr and |
| 19 | + exists(AstNode last, Completion c | |
| 20 | + CfgImpl::last(e, last, c) and |
| 21 | + last != e and |
| 22 | + c instanceof NormalCompletion |
| 23 | + ) |
| 24 | +} |
| 25 | + |
| 26 | +query predicate scopeNoFirst(CfgScope scope) { |
| 27 | + Consistency::scopeNoFirst(scope) and |
| 28 | + not scope = any(Function f | not exists(f.getBody())) and |
| 29 | + not scope = any(ClosureExpr c | not exists(c.getBody())) |
| 30 | +} |
| 31 | + |
| 32 | +/** Holds if `be` is the `else` branch of a `let` statement that results in a panic. */ |
| 33 | +private predicate letElsePanic(BlockExpr be) { |
| 34 | + be = any(LetStmt let).getLetElse().getBlockExpr() and |
| 35 | + exists(Completion c | CfgImpl::last(be, _, c) | completionIsNormal(c)) |
| 36 | +} |
| 37 | + |
| 38 | +query predicate deadEnd(CfgImpl::Node node) { |
| 39 | + Consistency::deadEnd(node) and |
| 40 | + not letElsePanic(node.getAstNode()) |
| 41 | +} |
0 commit comments