Skip to content

Commit 4a8ffea

Browse files
committed
Shared: Add control flow reachability lib.
1 parent 452bbf7 commit 4a8ffea

File tree

3 files changed

+965
-0
lines changed

3 files changed

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

0 commit comments

Comments
 (0)