diff --git a/csharp/ql/lib/semmle/code/csharp/dataflow/SSA.qll b/csharp/ql/lib/semmle/code/csharp/dataflow/SSA.qll index fc640cccf77..fee6bedf0f3 100644 --- a/csharp/ql/lib/semmle/code/csharp/dataflow/SSA.qll +++ b/csharp/ql/lib/semmle/code/csharp/dataflow/SSA.qll @@ -183,14 +183,7 @@ module Ssa { * Subsequent reads can be found by following the steps defined by * `AssignableRead.getANextRead()`. */ - AssignableRead ssaGetAFirstUse(SsaDefinition def) { - exists(ControlFlowNode cfn | - SsaImpl::firstReadSameVar(def, cfn) and - result.getControlFlowNode() = cfn - ) - } - - predicate isLiveOutRefParameterDefinition = SsaImpl::isLiveOutRefParameterDefinition/2; + AssignableRead ssaGetAFirstUse(SsaDefinition def) { SsaImpl::firstReadSameVar(def, result) } /** * DEPRECATED: Use `SsaDefinition` instead. @@ -350,7 +343,7 @@ module Ssa { * `AssignableRead.getANextRead()`. */ deprecated final AssignableRead getAFirstReadAtNode(ControlFlowNode cfn) { - SsaImpl::firstReadSameVar(this, cfn) and + SsaImpl::firstReadSameVar(this, result) and result.getControlFlowNode() = cfn } @@ -416,7 +409,7 @@ module Ssa { } /** - * DEPRECATED: Use `isLiveOutRefParameterDefinition(SsaDefinition, Parameter)` instead. + * DEPRECATED. * * Holds if this SSA definition assigns to `out`/`ref` parameter `p`, and the * parameter may remain unchanged throughout the rest of the enclosing callable. diff --git a/csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowPrivate.qll b/csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowPrivate.qll index ccf65ddb37c..f0d4bd99621 100644 --- a/csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowPrivate.qll +++ b/csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowPrivate.qll @@ -1605,7 +1605,7 @@ private module ReturnNodes { OutRefReturnNode() { exists(Parameter p | - Ssa::isLiveOutRefParameterDefinition(this.getDefinition(), p) and + SsaImpl::isLiveOutRefParameterDefinition(this.getDefinition(), p) and kind.getPosition() = p.getPosition() | p.isOut() and kind instanceof OutReturnKind diff --git a/csharp/ql/lib/semmle/code/csharp/dataflow/internal/SsaImpl.qll b/csharp/ql/lib/semmle/code/csharp/dataflow/internal/SsaImpl.qll index e248cf1c7e9..b7257a2f5f2 100644 --- a/csharp/ql/lib/semmle/code/csharp/dataflow/internal/SsaImpl.qll +++ b/csharp/ql/lib/semmle/code/csharp/dataflow/internal/SsaImpl.qll @@ -854,12 +854,14 @@ private module Cached { } /** - * Holds if the value defined at SSA definition `def` can reach a read at `cfn`, + * Holds if the value defined at SSA definition `def` can reach a read `read`, * without passing through any other read. */ cached - predicate firstReadSameVar(Definition def, ControlFlowNode cfn) { - exists(BasicBlock bb, int i | Impl::firstUse(def, bb, i, true) and cfn = bb.getNode(i)) + predicate firstReadSameVar(Definition def, AssignableRead read) { + exists(BasicBlock bb, int i | + Impl::firstUse(def, bb, i, true) and read.getControlFlowNode() = bb.getNode(i) + ) } /** diff --git a/csharp/ql/test/library-tests/dataflow/callablereturnsarg/Common.qll b/csharp/ql/test/library-tests/dataflow/callablereturnsarg/Common.qll index 2af01c72333..043ff2d1bc5 100644 --- a/csharp/ql/test/library-tests/dataflow/callablereturnsarg/Common.qll +++ b/csharp/ql/test/library-tests/dataflow/callablereturnsarg/Common.qll @@ -1,11 +1,12 @@ import csharp private import semmle.code.csharp.controlflow.Guards +private import semmle.code.csharp.dataflow.internal.SsaImpl as SsaImpl private predicate outRefDef(DataFlow::ExprNode ne, int outRef) { exists(SsaExplicitWrite def, Parameter outRefParameter | outRefParameter.isOutOrRef() and ne.getExpr() = def.getValue() and - Ssa::isLiveOutRefParameterDefinition(def, outRefParameter) and + SsaImpl::isLiveOutRefParameterDefinition(def, outRefParameter) and outRef = outRefParameter.getPosition() ) } diff --git a/csharp/ql/test/library-tests/dataflow/ssa/IsLiveOutRefParameterDefinition.ql b/csharp/ql/test/library-tests/dataflow/ssa/IsLiveOutRefParameterDefinition.ql index 130d91fb6fe..a8d2309d080 100644 --- a/csharp/ql/test/library-tests/dataflow/ssa/IsLiveOutRefParameterDefinition.ql +++ b/csharp/ql/test/library-tests/dataflow/ssa/IsLiveOutRefParameterDefinition.ql @@ -1,7 +1,8 @@ import csharp +private import semmle.code.csharp.dataflow.internal.SsaImpl as SsaImpl from Ssa::SourceVariable v, SsaDefinition def where v = def.getSourceVariable() and - Ssa::isLiveOutRefParameterDefinition(def, _) + SsaImpl::isLiveOutRefParameterDefinition(def, _) select v, def