Java: Replace getAFirstUse with top-level predicate.

This commit is contained in:
Anders Schack-Mulligen
2025-11-07 09:11:25 +01:00
parent 99aa0333cf
commit 07e635636c
7 changed files with 19 additions and 9 deletions

View File

@@ -140,6 +140,14 @@ class SsaSourceField extends SsaSourceVariable {
}
}
/**
* Gets an access of the SSA source variable underlying this SSA variable
* that can be reached from this SSA variable without passing through any
* other uses, but potentially through phi nodes and uncertain implicit
* updates.
*/
VarRead ssaGetAFirstUse(SsaDefinition def) { firstUse(def, result) }
/**
* An SSA variable.
*/
@@ -170,6 +178,8 @@ class SsaVariable extends Definition {
VarRead getAUse() { result = getAUse(this) }
/**
* DEPRECATED: Use `ssaGetAFirstUse(SsaDefinition)` instead.
*
* Gets an access of the SSA source variable underlying this SSA variable
* that can be reached from this SSA variable without passing through any
* other uses, but potentially through phi nodes and uncertain implicit
@@ -178,7 +188,7 @@ class SsaVariable extends Definition {
* Subsequent uses can be found by following the steps defined by
* `adjacentUseUse`.
*/
VarRead getAFirstUse() { firstUse(this, result) }
deprecated VarRead getAFirstUse() { firstUse(this, result) }
/** Holds if this SSA variable is live at the end of `b`. */
predicate isLiveAtEndOfBlock(BasicBlock b) { ssaDefReachesEndOfBlock(b, this) }

View File

@@ -465,7 +465,7 @@ private predicate enhancedForStmtStep(Node node1, Node node2, Type containerType
node1.asExpr() = e and
containerType = e.getType() and
v.getDefiningExpr() = for.getVariable() and
v.getAFirstUse() = node2.asExpr()
ssaGetAFirstUse(v) = node2.asExpr()
)
}

View File

@@ -401,7 +401,7 @@ class CastNode extends ExprNode {
any(SwitchStmt ss).getExpr(), any(SwitchExpr se).getExpr(),
any(InstanceOfExpr ioe).getExpr()
] and
this.asExpr() = upd.getAFirstUse()
this.asExpr() = ssaGetAFirstUse(upd)
)
}
}

View File

@@ -45,7 +45,7 @@ private class InputStreamWrapperCapturedLocalStep extends AdditionalTaintStep {
wrapper.getASourceSupertype+() instanceof TypeInputStream and
m.getDeclaringType() = wrapper and
capturer.captures(captured) and
TaintTracking::localTaint(DataFlow::exprNode(capturer.getAFirstUse()),
TaintTracking::localTaint(DataFlow::exprNode(ssaGetAFirstUse(capturer)),
any(DataFlow::PostUpdateNode pun |
pun.getPreUpdateNode().asExpr() = m.getParameter(0).getAnAccess()
)) and

View File

@@ -71,7 +71,7 @@ private class CommandArgumentList extends SsaExplicitUpdate {
/** Gets a use of the variable for which the list could be empty. */
private VarRead getAUseBeforeFirstAdd() {
result = this.getAFirstUse()
result = ssaGetAFirstUse(this)
or
exists(VarRead mid |
mid = this.getAUseBeforeFirstAdd() and
@@ -150,7 +150,7 @@ private class CommandArgumentArray extends SsaExplicitUpdate {
private class CommandArgArrayImmutableFirst extends CommandArgumentArray {
CommandArgArrayImmutableFirst() {
(exists(this.getAWrite(0)) or exists(firstElementOf(this.getDefiningExpr()))) and
forall(VarRead use | exists(this.getAWrite(0, use)) | use = this.getAFirstUse())
forall(VarRead use | exists(this.getAWrite(0, use)) | use = ssaGetAFirstUse(this))
}
/** Gets the first element of this array. */

View File

@@ -279,7 +279,7 @@ private module SinkModelGeneratorInput implements SinkModelGeneratorInputSig {
// exclude variable capture jump steps
exists(Ssa::SsaImplicitInit closure |
closure.captures(_) and
node.asExpr() = closure.getAFirstUse()
node.asExpr() = Ssa::ssaGetAFirstUse(closure)
)
}

View File

@@ -1,6 +1,6 @@
import java
import semmle.code.java.dataflow.SSA
from SsaVariable ssa, VarRead use
where use = ssa.getAFirstUse()
from SsaDefinition ssa, VarRead use
where use = ssaGetAFirstUse(ssa)
select ssa, use