Skip to content

Commit 124105f

Browse files
committed
Shared: Add control flow reachability lib.
1 parent 1d7bab9 commit 124105f

3 files changed

Lines changed: 939 additions & 0 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import java
2+
private import codeql.controlflow.ControlFlow
3+
private import semmle.code.java.dataflow.SSA as SSA
4+
private import semmle.code.java.controlflow.Guards as Guards
5+
6+
private module ControlFlowInput implements InputSig<Location, ControlFlowNode, BasicBlock> {
7+
private import java as J
8+
9+
AstNode getEnclosingAstNode(ControlFlowNode node) { node.getAstNode() = result }
10+
11+
class AstNode = ExprParent;
12+
13+
AstNode getParent(AstNode node) {
14+
result = node.(Expr).getParent() or
15+
result = node.(Stmt).getParent()
16+
}
17+
18+
class FinallyBlock extends AstNode {
19+
FinallyBlock() { any(TryStmt try).getFinally() = this }
20+
}
21+
22+
class Expr = J::Expr;
23+
24+
class SourceVariable = SSA::SsaSourceVariable;
25+
26+
class SsaDefinition = SSA::SsaVariable;
27+
28+
class SsaWriteDefinition extends SsaDefinition instanceof SSA::SsaExplicitUpdate {
29+
Expr getDefinition() {
30+
super.getDefiningExpr().(VariableAssign).getSource() = result or
31+
super.getDefiningExpr().(AssignOp) = result
32+
}
33+
}
34+
35+
class SsaPhiNode = SSA::SsaPhiNode;
36+
37+
class SsaUncertainDefinition extends SsaDefinition instanceof SSA::SsaUncertainImplicitUpdate {
38+
SsaDefinition getPriorDefinition() { result = super.getPriorDef() }
39+
}
40+
41+
class GuardValue = Guards::GuardValue;
42+
43+
predicate ssaControlsBranchEdge(SsaDefinition def, BasicBlock bb1, BasicBlock bb2, GuardValue v) {
44+
Guards::Guards_v3::ssaControlsBranchEdge(def, bb1, bb2, v)
45+
}
46+
47+
predicate ssaControls(SsaDefinition def, BasicBlock bb, GuardValue v) {
48+
Guards::Guards_v3::ssaControls(def, bb, v)
49+
}
50+
51+
import Guards::Guards_v3::InternalUtil
52+
}
53+
54+
module ControlFlow = Make<Location, Cfg, ControlFlowInput>;

0 commit comments

Comments
 (0)