C#: Address some review comments.

This commit is contained in:
Anders Schack-Mulligen
2026-05-04 11:49:24 +02:00
parent 1f3a8319ed
commit 02f5fe9a42
5 changed files with 13 additions and 16 deletions

View File

@@ -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.

View File

@@ -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

View File

@@ -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)
)
}
/**

View File

@@ -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()
)
}

View File

@@ -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