From ed6cdfc227f37e6b34d755699ca01aed1ce031d2 Mon Sep 17 00:00:00 2001 From: Anders Schack-Mulligen Date: Fri, 24 Apr 2026 08:47:36 +0200 Subject: [PATCH] C#: Move isLiveOutRefParameterDefinition to top-level. --- csharp/ql/lib/semmle/code/csharp/dataflow/SSA.qll | 6 +++++- .../code/csharp/dataflow/internal/DataFlowPrivate.qll | 4 ++-- .../ql/lib/semmle/code/csharp/dataflow/internal/SsaImpl.qll | 4 ++++ .../library-tests/dataflow/callablereturnsarg/Common.qll | 2 +- .../dataflow/ssa/IsLiveOutRefParameterDefinition.ql | 4 ++-- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/csharp/ql/lib/semmle/code/csharp/dataflow/SSA.qll b/csharp/ql/lib/semmle/code/csharp/dataflow/SSA.qll index 7d8809a700c..53866c77004 100644 --- a/csharp/ql/lib/semmle/code/csharp/dataflow/SSA.qll +++ b/csharp/ql/lib/semmle/code/csharp/dataflow/SSA.qll @@ -190,6 +190,8 @@ module Ssa { ) } + predicate isLiveOutRefParameterDefinition = SsaImpl::isLiveOutRefParameterDefinition/2; + /** * A static single assignment (SSA) definition. Either an explicit variable * definition (`ExplicitDefinition`), an implicit variable definition @@ -408,10 +410,12 @@ module Ssa { } /** + * DEPRECATED: Use `isLiveOutRefParameterDefinition(SsaDefinition, Parameter)` instead. + * * Holds if this SSA definition assigns to `out`/`ref` parameter `p`, and the * parameter may remain unchanged throughout the rest of the enclosing callable. */ - final predicate isLiveOutRefParameterDefinition(Parameter p) { + deprecated final predicate isLiveOutRefParameterDefinition(Parameter p) { SsaImpl::isLiveOutRefParameterDefinition(this, p) } 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 b6a6d398874..0f553b6e036 100644 --- a/csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowPrivate.qll +++ b/csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowPrivate.qll @@ -1244,7 +1244,7 @@ class SsaNode extends NodeImpl, TSsaNode { class SsaDefinitionNode extends SsaNode { override SsaImpl::DataFlowIntegration::SsaDefinitionNode node; - Ssa::Definition getDefinition() { result = node.getDefinition() } + SsaDefinition getDefinition() { result = node.getDefinition() } override ControlFlowNode getControlFlowNodeImpl() { result = this.getDefinition().getControlFlowNode() @@ -1613,7 +1613,7 @@ private module ReturnNodes { OutRefReturnNode() { exists(Parameter p | - this.getDefinition().isLiveOutRefParameterDefinition(p) and + Ssa::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 a4d788001a7..6966152475b 100644 --- a/csharp/ql/lib/semmle/code/csharp/dataflow/internal/SsaImpl.qll +++ b/csharp/ql/lib/semmle/code/csharp/dataflow/internal/SsaImpl.qll @@ -914,6 +914,10 @@ private module Cached { Impl::uncertainWriteDefinitionInput(def, result) } + /** + * Holds if the SSA definition `def` assigns to `out`/`ref` parameter `p`, and the + * parameter may remain unchanged throughout the rest of the enclosing callable. + */ cached predicate isLiveOutRefParameterDefinition(SsaDefinition def, Parameter p) { p.isOutOrRef() and diff --git a/csharp/ql/test/library-tests/dataflow/callablereturnsarg/Common.qll b/csharp/ql/test/library-tests/dataflow/callablereturnsarg/Common.qll index 3a3a55e42cc..95a93e24a2a 100644 --- a/csharp/ql/test/library-tests/dataflow/callablereturnsarg/Common.qll +++ b/csharp/ql/test/library-tests/dataflow/callablereturnsarg/Common.qll @@ -5,7 +5,7 @@ private predicate outRefDef(DataFlow::ExprNode ne, int outRef) { exists(Ssa::ExplicitDefinition def, Parameter outRefParameter | outRefParameter.isOutOrRef() and ne.getExpr() = def.getADefinition().getSource() and - def.isLiveOutRefParameterDefinition(outRefParameter) and + Ssa::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 ca43b497dd5..130d91fb6fe 100644 --- a/csharp/ql/test/library-tests/dataflow/ssa/IsLiveOutRefParameterDefinition.ql +++ b/csharp/ql/test/library-tests/dataflow/ssa/IsLiveOutRefParameterDefinition.ql @@ -1,7 +1,7 @@ import csharp -from Ssa::SourceVariable v, Ssa::Definition def +from Ssa::SourceVariable v, SsaDefinition def where v = def.getSourceVariable() and - def.isLiveOutRefParameterDefinition(_) + Ssa::isLiveOutRefParameterDefinition(def, _) select v, def