Skip to content

Commit 07e6356

Browse files
committed
Java: Replace getAFirstUse with top-level predicate.
1 parent 99aa033 commit 07e6356

File tree

7 files changed

+19
-9
lines changed

7 files changed

+19
-9
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,14 @@ class SsaSourceField extends SsaSourceVariable {
140140
}
141141
}
142142

143+
/**
144+
* Gets an access of the SSA source variable underlying this SSA variable
145+
* that can be reached from this SSA variable without passing through any
146+
* other uses, but potentially through phi nodes and uncertain implicit
147+
* updates.
148+
*/
149+
VarRead ssaGetAFirstUse(SsaDefinition def) { firstUse(def, result) }
150+
143151
/**
144152
* An SSA variable.
145153
*/
@@ -170,6 +178,8 @@ class SsaVariable extends Definition {
170178
VarRead getAUse() { result = getAUse(this) }
171179

172180
/**
181+
* DEPRECATED: Use `ssaGetAFirstUse(SsaDefinition)` instead.
182+
*
173183
* Gets an access of the SSA source variable underlying this SSA variable
174184
* that can be reached from this SSA variable without passing through any
175185
* other uses, but potentially through phi nodes and uncertain implicit
@@ -178,7 +188,7 @@ class SsaVariable extends Definition {
178188
* Subsequent uses can be found by following the steps defined by
179189
* `adjacentUseUse`.
180190
*/
181-
VarRead getAFirstUse() { firstUse(this, result) }
191+
deprecated VarRead getAFirstUse() { firstUse(this, result) }
182192

183193
/** Holds if this SSA variable is live at the end of `b`. */
184194
predicate isLiveAtEndOfBlock(BasicBlock b) { ssaDefReachesEndOfBlock(b, this) }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ private predicate enhancedForStmtStep(Node node1, Node node2, Type containerType
465465
node1.asExpr() = e and
466466
containerType = e.getType() and
467467
v.getDefiningExpr() = for.getVariable() and
468-
v.getAFirstUse() = node2.asExpr()
468+
ssaGetAFirstUse(v) = node2.asExpr()
469469
)
470470
}
471471

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ class CastNode extends ExprNode {
401401
any(SwitchStmt ss).getExpr(), any(SwitchExpr se).getExpr(),
402402
any(InstanceOfExpr ioe).getExpr()
403403
] and
404-
this.asExpr() = upd.getAFirstUse()
404+
this.asExpr() = ssaGetAFirstUse(upd)
405405
)
406406
}
407407
}

java/ql/lib/semmle/code/java/frameworks/InputStream.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private class InputStreamWrapperCapturedLocalStep extends AdditionalTaintStep {
4545
wrapper.getASourceSupertype+() instanceof TypeInputStream and
4646
m.getDeclaringType() = wrapper and
4747
capturer.captures(captured) and
48-
TaintTracking::localTaint(DataFlow::exprNode(capturer.getAFirstUse()),
48+
TaintTracking::localTaint(DataFlow::exprNode(ssaGetAFirstUse(capturer)),
4949
any(DataFlow::PostUpdateNode pun |
5050
pun.getPreUpdateNode().asExpr() = m.getParameter(0).getAnAccess()
5151
)) and

java/ql/lib/semmle/code/java/security/CommandArguments.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private class CommandArgumentList extends SsaExplicitUpdate {
7171

7272
/** Gets a use of the variable for which the list could be empty. */
7373
private VarRead getAUseBeforeFirstAdd() {
74-
result = this.getAFirstUse()
74+
result = ssaGetAFirstUse(this)
7575
or
7676
exists(VarRead mid |
7777
mid = this.getAUseBeforeFirstAdd() and
@@ -150,7 +150,7 @@ private class CommandArgumentArray extends SsaExplicitUpdate {
150150
private class CommandArgArrayImmutableFirst extends CommandArgumentArray {
151151
CommandArgArrayImmutableFirst() {
152152
(exists(this.getAWrite(0)) or exists(firstElementOf(this.getDefiningExpr()))) and
153-
forall(VarRead use | exists(this.getAWrite(0, use)) | use = this.getAFirstUse())
153+
forall(VarRead use | exists(this.getAWrite(0, use)) | use = ssaGetAFirstUse(this))
154154
}
155155

156156
/** Gets the first element of this array. */

java/ql/src/utils/modelgenerator/internal/CaptureModels.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ private module SinkModelGeneratorInput implements SinkModelGeneratorInputSig {
279279
// exclude variable capture jump steps
280280
exists(Ssa::SsaImplicitInit closure |
281281
closure.captures(_) and
282-
node.asExpr() = closure.getAFirstUse()
282+
node.asExpr() = Ssa::ssaGetAFirstUse(closure)
283283
)
284284
}
285285

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

4-
from SsaVariable ssa, VarRead use
5-
where use = ssa.getAFirstUse()
4+
from SsaDefinition ssa, VarRead use
5+
where use = ssaGetAFirstUse(ssa)
66
select ssa, use

0 commit comments

Comments
 (0)