Skip to content

Commit f0bd034

Browse files
committed
Java: Replace usages of SsaVariable.
1 parent 8594ae0 commit f0bd034

File tree

7 files changed

+23
-21
lines changed

7 files changed

+23
-21
lines changed

java/ql/lib/semmle/code/java/dataflow/NullGuards.qll

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Expr clearlyNotNullExpr(Expr reason) {
108108
}
109109

110110
/** Holds if `v` is an SSA variable that is provably not `null`. */
111-
predicate clearlyNotNull(SsaVariable v, Expr reason) {
111+
predicate clearlyNotNull(SsaDefinition v, Expr reason) {
112112
exists(Expr src |
113113
src = v.(SsaExplicitWrite).getValue() and
114114
src = clearlyNotNullExpr(reason)
@@ -136,7 +136,7 @@ predicate clearlyNotNull(SsaVariable v, Expr reason) {
136136
Expr clearlyNotNullExpr() { result = clearlyNotNullExpr(_) }
137137

138138
/** Holds if `v` is an SSA variable that is provably not `null`. */
139-
predicate clearlyNotNull(SsaVariable v) { clearlyNotNull(v, _) }
139+
predicate clearlyNotNull(SsaDefinition v) { clearlyNotNull(v, _) }
140140

141141
/**
142142
* Holds if the evaluation of a call to `m` resulting in the value `branch`
@@ -207,7 +207,7 @@ deprecated Expr basicOrCustomNullGuard(Expr e, boolean branch, boolean isnull) {
207207
* If `result` evaluates to `branch`, then `v` is guaranteed to be null if `isnull`
208208
* is true, and non-null if `isnull` is false.
209209
*/
210-
Expr directNullGuard(SsaVariable v, boolean branch, boolean isnull) {
210+
Expr directNullGuard(SsaDefinition v, boolean branch, boolean isnull) {
211211
result = basicNullGuard(sameValue(v, _), branch, isnull)
212212
}
213213

@@ -219,7 +219,7 @@ Expr directNullGuard(SsaVariable v, boolean branch, boolean isnull) {
219219
* If `result` evaluates to `branch`, then `v` is guaranteed to be null if `isnull`
220220
* is true, and non-null if `isnull` is false.
221221
*/
222-
deprecated Guard nullGuard(SsaVariable v, boolean branch, boolean isnull) {
222+
deprecated Guard nullGuard(SsaDefinition v, boolean branch, boolean isnull) {
223223
result = directNullGuard(v, branch, isnull)
224224
}
225225

@@ -228,7 +228,9 @@ deprecated Guard nullGuard(SsaVariable v, boolean branch, boolean isnull) {
228228
* from `bb1` to `bb2` implies that `v` is guaranteed to be null if `isnull` is
229229
* true, and non-null if `isnull` is false.
230230
*/
231-
predicate nullGuardControlsBranchEdge(SsaVariable v, boolean isnull, BasicBlock bb1, BasicBlock bb2) {
231+
predicate nullGuardControlsBranchEdge(
232+
SsaDefinition v, boolean isnull, BasicBlock bb1, BasicBlock bb2
233+
) {
232234
exists(GuardValue gv |
233235
Guards_v3::ssaControlsBranchEdge(v, bb1, bb2, gv) and
234236
gv.isNullness(isnull)
@@ -240,7 +242,7 @@ predicate nullGuardControlsBranchEdge(SsaVariable v, boolean isnull, BasicBlock
240242
* `bb` `v` is guaranteed to be null if `isnull` is true, and non-null if
241243
* `isnull` is false.
242244
*/
243-
predicate nullGuardControls(SsaVariable v, boolean isnull, BasicBlock bb) {
245+
predicate nullGuardControls(SsaDefinition v, boolean isnull, BasicBlock bb) {
244246
exists(GuardValue gv |
245247
Guards_v3::ssaControls(v, bb, gv) and
246248
gv.isNullness(isnull)
@@ -263,6 +265,6 @@ predicate guardSuggestsExprMaybeNull(Expr guard, Expr e) {
263265
/**
264266
* Holds if `guard` is a guard expression that suggests that `v` might be null.
265267
*/
266-
predicate guardSuggestsVarMaybeNull(Expr guard, SsaVariable v) {
268+
predicate guardSuggestsVarMaybeNull(Expr guard, SsaDefinition v) {
267269
guardSuggestsExprMaybeNull(guard, sameValue(v, _))
268270
}

java/ql/lib/semmle/code/java/dataflow/Nullness.qll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@ predicate dereference(Expr e) {
113113
*
114114
* The `VarAccess` is included for nicer error reporting.
115115
*/
116-
private ControlFlowNode varDereference(SsaVariable v, VarAccess va) {
116+
private ControlFlowNode varDereference(SsaDefinition v, VarAccess va) {
117117
dereference(result.asExpr()) and
118118
result.asExpr() = sameValue(v, va)
119119
}
120120

121121
/**
122122
* The first dereference of a variable in a given `BasicBlock`.
123123
*/
124-
private predicate firstVarDereferenceInBlock(BasicBlock bb, SsaVariable v, VarAccess va) {
124+
private predicate firstVarDereferenceInBlock(BasicBlock bb, SsaDefinition v, VarAccess va) {
125125
exists(ControlFlowNode n |
126126
varDereference(v, va) = n and
127127
n.getBasicBlock() = bb and
@@ -135,13 +135,13 @@ private predicate firstVarDereferenceInBlock(BasicBlock bb, SsaVariable v, VarAc
135135
}
136136

137137
/** A variable suspected of being `null`. */
138-
private predicate varMaybeNull(SsaVariable v, ControlFlowNode node, string msg, Expr reason) {
138+
private predicate varMaybeNull(SsaDefinition v, ControlFlowNode node, string msg, Expr reason) {
139139
// A variable compared to null might be null.
140140
exists(Expr e |
141141
reason = e and
142142
msg = "as suggested by $@ null guard" and
143143
guardSuggestsVarMaybeNull(e, v) and
144-
node = v.getCfgNode() and
144+
node = v.getControlFlowNode() and
145145
not v instanceof SsaPhiDefinition and
146146
not clearlyNotNull(v) and
147147
// Comparisons in finally blocks are excluded since missing exception edges in the CFG could otherwise yield FPs.
@@ -157,7 +157,7 @@ private predicate varMaybeNull(SsaVariable v, ControlFlowNode node, string msg,
157157
// A parameter might be null if there is a null argument somewhere.
158158
exists(Parameter p, Expr arg |
159159
v.(SsaParameterInit).getParameter() = p and
160-
node = v.getCfgNode() and
160+
node = v.getControlFlowNode() and
161161
p.getAnArgument() = arg and
162162
reason = arg and
163163
msg = "because of $@ null argument" and
@@ -266,7 +266,7 @@ private module NullnessFlow = ControlFlowReachability::Flow<NullnessConfig>;
266266
* Holds if the dereference of `v` at `va` might be `null`.
267267
*/
268268
predicate nullDeref(SsaSourceVariable v, VarAccess va, string msg, Expr reason) {
269-
exists(SsaVariable origin, SsaVariable ssa, ControlFlowNode src, ControlFlowNode sink |
269+
exists(SsaDefinition origin, SsaDefinition ssa, ControlFlowNode src, ControlFlowNode sink |
270270
varMaybeNull(origin, src, msg, reason) and
271271
NullnessFlow::flow(src, origin, sink, ssa) and
272272
ssa.getSourceVariable() = v and

java/ql/lib/semmle/code/java/dataflow/RangeUtils.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ predicate eqFlowCond = U::eqFlowCond/5;
3333
* `SsaPhiDefinition` in order for the reflexive case of `nonNullSsaFwdStep*(..)` to
3434
* have non-`SsaPhiDefinition` results.
3535
*/
36-
private predicate nonNullSsaFwdStep(SsaVariable v, SsaVariable phi) {
36+
private predicate nonNullSsaFwdStep(SsaDefinition v, SsaDefinition phi) {
3737
exists(SsaExplicitWrite vnull, SsaPhiDefinition phi0 | phi0 = phi |
3838
2 = strictcount(phi0.getAnInput()) and
3939
vnull = phi0.getAnInput() and
@@ -56,13 +56,13 @@ private predicate nonNullDefStep(Expr e1, Expr e2) {
5656
* explicit `ArrayCreationExpr` definition and that the definition does not go
5757
* through a back edge.
5858
*/
59-
ArrayCreationExpr getArrayDef(SsaVariable v) {
59+
ArrayCreationExpr getArrayDef(SsaDefinition v) {
6060
exists(Expr src |
6161
v.(SsaExplicitWrite).getValue() = src and
6262
nonNullDefStep*(result, src)
6363
)
6464
or
65-
exists(SsaVariable mid |
65+
exists(SsaDefinition mid |
6666
result = getArrayDef(mid) and
6767
nonNullSsaFwdStep(mid, v)
6868
)

java/ql/lib/semmle/code/java/dataflow/SSA.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class SsaSourceVariable extends TSsaSourceVariable {
105105
SsaSourceVariable getQualifier() { this = TQualifiedField(_, result, _) }
106106

107107
/** Gets an SSA variable that has this variable as its underlying source variable. */
108-
SsaVariable getAnSsaVariable() { result.getSourceVariable() = this }
108+
SsaDefinition getAnSsaVariable() { result.getSourceVariable() = this }
109109
}
110110

111111
/**

java/ql/lib/semmle/code/java/dataflow/internal/SsaImpl.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ private module Cached {
510510

511511
/** Holds if `init` is a closure variable that captures the value of `capturedvar`. */
512512
cached
513-
predicate captures(SsaImplicitEntryDefinition init, SsaVariable capturedvar) {
513+
predicate captures(SsaImplicitEntryDefinition init, SsaDefinition capturedvar) {
514514
exists(BasicBlock bb, int i |
515515
Ssa::ssaDefReachesUncertainRead(_, capturedvar, bb, i) and
516516
variableCapture(capturedvar.getSourceVariable(), init.getSourceVariable(), bb, i)

java/ql/lib/semmle/code/java/dataflow/internal/rangeanalysis/SignAnalysisSpecific.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module Private {
1717

1818
class Guard = G::Guards_v2::Guard;
1919

20-
class SsaVariable = Ssa::SsaVariable;
20+
class SsaVariable = Ssa::SsaDefinition;
2121

2222
class SsaPhiNode = Ssa::SsaPhiDefinition;
2323

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import java
22
import semmle.code.java.dataflow.SSA
33

4-
from SsaVariable ssa, SsaSourceVariable v, string s
4+
from SsaDefinition ssa, SsaSourceVariable v, string s
55
where
66
ssa.getSourceVariable() = v and
77
(
88
s = ssa.toString()
99
or
1010
not exists(ssa.toString()) and s = "error"
1111
)
12-
select v, ssa.getCfgNode(), s
12+
select v, ssa.getControlFlowNode(), s

0 commit comments

Comments
 (0)