|
| 1 | +/** |
| 2 | + * Provides an implementation of local (intraprocedural) control flow reachability. |
| 3 | + */ |
| 4 | + |
| 5 | +import csharp |
| 6 | +private import codeql.controlflow.ControlFlowReachability |
| 7 | +private import semmle.code.csharp.controlflow.BasicBlocks |
| 8 | +private import semmle.code.csharp.controlflow.Guards as Guards |
| 9 | +private import semmle.code.csharp.ExprOrStmtParent |
| 10 | + |
| 11 | +private module ControlFlowInput implements |
| 12 | + InputSig<Location, ControlFlow::Node, ControlFlow::BasicBlock> |
| 13 | +{ |
| 14 | + private import csharp as CS |
| 15 | + |
| 16 | + AstNode getEnclosingAstNode(ControlFlow::Node node) { |
| 17 | + node.getAstNode() = result |
| 18 | + or |
| 19 | + not exists(node.getAstNode()) and result = node.getEnclosingCallable() |
| 20 | + } |
| 21 | + |
| 22 | + class AstNode = ExprOrStmtParent; |
| 23 | + |
| 24 | + AstNode getParent(AstNode node) { result = node.getParent() } |
| 25 | + |
| 26 | + class FinallyBlock extends AstNode { |
| 27 | + FinallyBlock() { any(TryStmt try).getFinally() = this } |
| 28 | + } |
| 29 | + |
| 30 | + class Expr = CS::Expr; |
| 31 | + |
| 32 | + class SourceVariable = Ssa::SourceVariable; |
| 33 | + |
| 34 | + class SsaDefinition = Ssa::Definition; |
| 35 | + |
| 36 | + class SsaExplicitWrite extends SsaDefinition instanceof Ssa::ExplicitDefinition { |
| 37 | + Expr getValue() { result = super.getADefinition().getSource() } |
| 38 | + } |
| 39 | + |
| 40 | + class SsaPhiDefinition = Ssa::PhiNode; |
| 41 | + |
| 42 | + class SsaUncertainWrite = Ssa::UncertainDefinition; |
| 43 | + |
| 44 | + class GuardValue = Guards::GuardValue; |
| 45 | + |
| 46 | + predicate ssaControlsBranchEdge(SsaDefinition def, BasicBlock bb1, BasicBlock bb2, GuardValue v) { |
| 47 | + Guards::Guards::ssaControlsBranchEdge(def, bb1, bb2, v) |
| 48 | + } |
| 49 | + |
| 50 | + predicate ssaControls(SsaDefinition def, BasicBlock bb, GuardValue v) { |
| 51 | + Guards::Guards::ssaControls(def, bb, v) |
| 52 | + } |
| 53 | + |
| 54 | + import Guards::Guards::InternalUtil |
| 55 | +} |
| 56 | + |
| 57 | +module ControlFlowReachability = Make<Location, Cfg, ControlFlowInput>; |
0 commit comments