Skip to content

Commit 228ec2e

Browse files
committed
Java: Get rid of untracked SSA definitions.
1 parent 44546c3 commit 228ec2e

File tree

2 files changed

+6
-38
lines changed

2 files changed

+6
-38
lines changed

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,10 @@ class SsaVariable extends Definition {
148148
/** Gets the `ControlFlowNode` at which this SSA variable is defined. */
149149
pragma[nomagic]
150150
ControlFlowNode getCfgNode() {
151-
exists(BasicBlock bb, int i, int j |
151+
exists(BasicBlock bb, int i |
152152
this.definesAt(_, bb, i) and
153-
// untracked definitions are inserted just before reads
154-
(if this instanceof UntrackedDef then j = i + 1 else j = i) and
155153
// phi nodes are inserted at position `-1`
156-
result = bb.getNode(0.maximum(j))
154+
result = bb.getNode(0.maximum(i))
157155
)
158156
}
159157

@@ -246,8 +244,6 @@ class SsaImplicitUpdate extends SsaUpdate {
246244
}
247245

248246
private string getKind() {
249-
this instanceof UntrackedDef and result = "untracked"
250-
or
251247
this.hasExplicitQualifierUpdate() and
252248
result = "explicit qualifier"
253249
or
@@ -280,8 +276,6 @@ class SsaImplicitUpdate extends SsaUpdate {
280276
* of its qualifiers is volatile.
281277
*/
282278
predicate assignsUnknownValue() {
283-
this instanceof UntrackedDef
284-
or
285279
this.hasExplicitQualifierUpdate()
286280
or
287281
this.hasImplicitQualifierUpdate()

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

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,6 @@ private module TrackedVariablesImpl {
8282

8383
private import TrackedVariablesImpl
8484

85-
private predicate untrackedFieldWrite(BasicBlock bb, int i, SsaSourceVariable v) {
86-
v =
87-
any(SsaSourceField nf |
88-
bb.getNode(i + 1) = nf.getAnAccess().(FieldRead).getControlFlowNode() and not trackField(nf)
89-
)
90-
}
91-
9285
/** Gets the definition point of a nested class in the parent scope. */
9386
private ControlFlowNode parentDef(NestedClass nc) {
9487
nc.(AnonymousClass).getClassInstanceExpr().getControlFlowNode() = result or
@@ -184,9 +177,6 @@ private module SsaInput implements SsaImplCommon::InputSig<Location, BasicBlock>
184177
certainVariableUpdate(v, _, bb, i) and
185178
certain = true
186179
or
187-
untrackedFieldWrite(bb, i, v) and
188-
certain = true
189-
or
190180
hasEntryDef(v, bb) and
191181
i = -1 and
192182
certain = true
@@ -204,7 +194,10 @@ private module SsaInput implements SsaImplCommon::InputSig<Location, BasicBlock>
204194
hasDominanceInformation(bb) and
205195
(
206196
exists(VarRead use |
207-
v.getAnAccess() = use and bb.getNode(i) = use.getControlFlowNode() and certain = true
197+
v instanceof TrackedVar and
198+
v.getAnAccess() = use and
199+
bb.getNode(i) = use.getControlFlowNode() and
200+
certain = true
208201
)
209202
or
210203
variableCapture(v, _, bb, i) and
@@ -223,16 +216,6 @@ final class UncertainWriteDefinition = Impl::UncertainWriteDefinition;
223216

224217
final class PhiNode = Impl::PhiNode;
225218

226-
class UntrackedDef extends Definition {
227-
private VarRead read;
228-
229-
UntrackedDef() { ssaUntrackedDef(this, read) }
230-
231-
string toString() { result = read.toString() }
232-
233-
Location getLocation() { result = read.getLocation() }
234-
}
235-
236219
cached
237220
private module Cached {
238221
/** Gets the destination variable of an update of a tracked variable. */
@@ -256,15 +239,6 @@ private module Cached {
256239
)
257240
}
258241

259-
cached
260-
predicate ssaUntrackedDef(Definition def, VarRead read) {
261-
exists(SsaSourceVariable v, BasicBlock bb, int i |
262-
def.definesAt(v, bb, i) and
263-
untrackedFieldWrite(bb, i, v) and
264-
read.getControlFlowNode() = bb.getNode(i + 1)
265-
)
266-
}
267-
268242
/*
269243
* The SSA construction for a field `f` relies on implicit update nodes at
270244
* every call site that conceivably could reach an update of the field.

0 commit comments

Comments
 (0)