Repository navigation
Expand file tree
/
Copy pathDefUse.qll
More file actions
58 lines (53 loc) · 1.99 KB
/
Copy pathDefUse.qll
File metadata and controls
58 lines (53 loc) · 1.99 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* Provides classes and predicates for def-use and use-use pairs. Built on top of the SSA library for
* maximal precision.
*/
overlay[local?]
module;
import java
private import SSA
/**
* Holds if `use1` and `use2` form a use-use-pair of the same SSA variable,
* that is, the value read in `use1` can reach `use2` without passing through
* any SSA definition of the variable.
*
* This is the transitive closure of `adjacentUseUseSameVar`.
*/
predicate useUsePairSameVar(VarRead use1, VarRead use2) { adjacentUseUseSameVar+(use1, use2) }
/**
* Holds if `use1` and `use2` form a use-use-pair of the same
* `SsaSourceVariable`, that is, the value read in `use1` can reach `use2`
* without passing through any SSA definition of the variable except for phi
* nodes and uncertain implicit updates.
*
* This is the transitive closure of `adjacentUseUse`.
*/
predicate useUsePair(VarRead use1, VarRead use2) { adjacentUseUse+(use1, use2) }
/**
* Holds if there exists a path from `def` to `use` without passing through another
* `VariableUpdate` of the `LocalScopeVariable` that they both refer to.
*
* Other paths may also exist, so the SSA variables in `def` and `use` can be different.
*/
predicate defUsePair(VariableUpdate def, VarRead use) {
exists(SsaDefinition v, SsaExplicitWrite write |
v.getARead() = use and write.getDefiningExpr() = def
|
v.getAnUltimateDefinition() = write
or
v.(SsaCapturedDefinition).getAnUltimateCapturedDefinition() = write
)
}
/**
* Holds if there exists a path from the entry-point of the callable to `use` without
* passing through a `VariableUpdate` of the parameter `p` that `use` refers to.
*
* Other paths may also exist, so the SSA variables can be different.
*/
predicate parameterDefUsePair(Parameter p, VarRead use) {
exists(SsaDefinition v, SsaParameterInit init | v.getARead() = use and init.getParameter() = p |
v.getAnUltimateDefinition() = init
or
v.(SsaCapturedDefinition).getAnUltimateCapturedDefinition() = init
)
}