-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathssa.ql
42 lines (34 loc) · 1.3 KB
/
ssa.ql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import codeql.ruby.AST
import codeql.ruby.CFG
import codeql.ruby.dataflow.SSA
import codeql.ruby.dataflow.internal.SsaImpl
import Impl::TestAdjacentRefs as RefTest
query predicate definition(Ssa::Definition def, Variable v) { def.getSourceVariable() = v }
query predicate read(Ssa::Definition def, Variable v, CfgNode read) {
def.getSourceVariable() = v and read = def.getARead()
}
query predicate firstRead(Ssa::Definition def, Variable v, CfgNode read) {
def.getSourceVariable() = v and read = def.getAFirstRead()
}
query predicate adjacentReads(Ssa::Definition def, Variable v, CfgNode read1, CfgNode read2) {
def.getSourceVariable() = v and
def.hasAdjacentReads(read1, read2)
}
query predicate phi(Ssa::PhiNode phi, Variable v, Ssa::Definition input) {
phi.getSourceVariable() = v and input = phi.getAnInput()
}
query predicate phiReadNode(RefTest::Ref phi, Variable v) {
phi.isPhiRead() and phi.getSourceVariable() = v
}
query predicate phiReadNodeFirstRead(RefTest::Ref phi, Variable v, CfgNode read) {
exists(RefTest::Ref r, BasicBlock bb, int i |
phi.isPhiRead() and
RefTest::adjacentRefRead(phi, r) and
r.accessAt(bb, i, v) and
read = bb.getNode(i)
)
}
query predicate phiReadInput(RefTest::Ref phi, RefTest::Ref inp) {
phi.isPhiRead() and
RefTest::adjacentRefPhi(inp, phi)
}