From 95ac61df42be5d5b18a479cd216f07d990d84011 Mon Sep 17 00:00:00 2001 From: Anders Schack-Mulligen Date: Mon, 27 Oct 2025 12:50:11 +0100 Subject: [PATCH] Java: Drop caching of deprecated predicates. --- .../code/java/dataflow/internal/SsaImpl.qll | 109 ++++++++---------- 1 file changed, 51 insertions(+), 58 deletions(-) diff --git a/java/ql/lib/semmle/code/java/dataflow/internal/SsaImpl.qll b/java/ql/lib/semmle/code/java/dataflow/internal/SsaImpl.qll index 34bb39a8509..21843f3e93b 100644 --- a/java/ql/lib/semmle/code/java/dataflow/internal/SsaImpl.qll +++ b/java/ql/lib/semmle/code/java/dataflow/internal/SsaImpl.qll @@ -244,6 +244,53 @@ final class UncertainWriteDefinition = Impl::UncertainWriteDefinition; final class PhiNode = Impl::PhiNode; +predicate ssaExplicitUpdate(SsaUpdate def, VariableUpdate upd) { + exists(SsaSourceVariable v, BasicBlock bb, int i | + def.definesAt(v, bb, i) and + certainVariableUpdate(v, upd.getControlFlowNode(), bb, i) and + getDestVar(upd) = def.getSourceVariable() + ) +} + +deprecated predicate ssaUncertainImplicitUpdate(SsaImplicitUpdate def) { + exists(SsaSourceVariable v, BasicBlock bb, int i | + def.definesAt(v, bb, i) and + uncertainVariableUpdate(v, _, bb, i) + ) +} + +predicate ssaImplicitInit(WriteDefinition def) { + exists(SsaSourceVariable v, BasicBlock bb, int i | + def.definesAt(v, bb, i) and + hasEntryDef(v, bb) and + i = -1 + ) +} + +/** + * Holds if the SSA definition of `v` at `def` reaches `redef` without crossing another + * SSA definition of `v`. + */ +deprecated predicate ssaDefReachesUncertainDef(TrackedSsaDef def, SsaUncertainImplicitUpdate redef) { + Impl::uncertainWriteDefinitionInput(redef, def) +} + +VarRead getAUse(Definition def) { + exists(SsaSourceVariable v, BasicBlock bb, int i | + Impl::ssaDefReachesRead(v, def, bb, i) and + result.getControlFlowNode() = bb.getNode(i) and + result = v.getAnAccess() + ) +} + +predicate ssaDefReachesEndOfBlock(BasicBlock bb, Definition def) { + Impl::ssaDefReachesEndOfBlock(bb, def, _) +} + +deprecated predicate phiHasInputFromBlock(PhiNode phi, Definition inp, BasicBlock bb) { + Impl::phiHasInputFromBlock(phi, inp, bb) +} + cached private module Cached { /** Gets the destination variable of an update of a tracked variable. */ @@ -258,15 +305,6 @@ private module Cached { result.getAnAccess() = upd.(UnaryAssignExpr).getExpr() } - cached - predicate ssaExplicitUpdate(SsaUpdate def, VariableUpdate upd) { - exists(SsaSourceVariable v, BasicBlock bb, int i | - def.definesAt(v, bb, i) and - certainVariableUpdate(v, upd.getControlFlowNode(), bb, i) and - getDestVar(upd) = def.getSourceVariable() - ) - } - /* * The SSA construction for a field `f` relies on implicit update nodes at * every call site that conceivably could reach an update of the field. @@ -486,26 +524,9 @@ private module Cached { overlay[global] cached - predicate defUpdatesNamedField(SsaImplicitWrite def, TrackedField f, Callable setter) { - f = def.getSourceVariable() and - updatesNamedField0(def.getControlFlowNode().asCall(), f, setter) - } - - cached - deprecated predicate ssaUncertainImplicitUpdate(SsaImplicitUpdate def) { - exists(SsaSourceVariable v, BasicBlock bb, int i | - def.definesAt(v, bb, i) and - uncertainVariableUpdate(v, _, bb, i) - ) - } - - cached - predicate ssaImplicitInit(WriteDefinition def) { - exists(SsaSourceVariable v, BasicBlock bb, int i | - def.definesAt(v, bb, i) and - hasEntryDef(v, bb) and - i = -1 - ) + predicate defUpdatesNamedField(SsaImplicitWrite calldef, TrackedField f, Callable setter) { + f = calldef.getSourceVariable() and + updatesNamedField0(calldef.getControlFlowNode().asCall(), f, setter) } /** Holds if `init` is a closure variable that captures the value of `capturedvar`. */ @@ -517,15 +538,6 @@ private module Cached { ) } - /** - * Holds if the SSA definition of `v` at `def` reaches `redef` without crossing another - * SSA definition of `v`. - */ - cached - deprecated predicate ssaDefReachesUncertainDef(TrackedSsaDef def, SsaUncertainImplicitUpdate redef) { - Impl::uncertainWriteDefinitionInput(redef, def) - } - /** * Holds if the value defined at `def` can reach `use` without passing through * any other uses, but possibly through phi nodes and uncertain implicit updates. @@ -538,25 +550,6 @@ private module Cached { ) } - cached - VarRead getAUse(Definition def) { - exists(SsaSourceVariable v, BasicBlock bb, int i | - Impl::ssaDefReachesRead(v, def, bb, i) and - result.getControlFlowNode() = bb.getNode(i) and - result = v.getAnAccess() - ) - } - - cached - predicate ssaDefReachesEndOfBlock(BasicBlock bb, Definition def) { - Impl::ssaDefReachesEndOfBlock(bb, def, _) - } - - cached - predicate phiHasInputFromBlock(PhiNode phi, Definition inp, BasicBlock bb) { - Impl::phiHasInputFromBlock(phi, inp, bb) - } - cached module DataFlowIntegration { import DataFlowIntegrationImpl @@ -666,7 +659,7 @@ private module DataFlowIntegrationInput implements Impl::DataFlowIntegrationInpu } } - Expr getARead(Definition def) { result = getAUse(def) } + Expr getARead(Definition def) { result = def.(SsaDefinition).getARead() } predicate ssaDefHasSource(WriteDefinition def) { def instanceof SsaExplicitWrite }