Skip to content

Commit 02f5fe9

Browse files
committed
C#: Address some review comments.
1 parent 1f3a831 commit 02f5fe9

5 files changed

Lines changed: 13 additions & 16 deletions

File tree

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,7 @@ module Ssa {
183183
* Subsequent reads can be found by following the steps defined by
184184
* `AssignableRead.getANextRead()`.
185185
*/
186-
AssignableRead ssaGetAFirstUse(SsaDefinition def) {
187-
exists(ControlFlowNode cfn |
188-
SsaImpl::firstReadSameVar(def, cfn) and
189-
result.getControlFlowNode() = cfn
190-
)
191-
}
192-
193-
predicate isLiveOutRefParameterDefinition = SsaImpl::isLiveOutRefParameterDefinition/2;
186+
AssignableRead ssaGetAFirstUse(SsaDefinition def) { SsaImpl::firstReadSameVar(def, result) }
194187

195188
/**
196189
* DEPRECATED: Use `SsaDefinition` instead.
@@ -350,7 +343,7 @@ module Ssa {
350343
* `AssignableRead.getANextRead()`.
351344
*/
352345
deprecated final AssignableRead getAFirstReadAtNode(ControlFlowNode cfn) {
353-
SsaImpl::firstReadSameVar(this, cfn) and
346+
SsaImpl::firstReadSameVar(this, result) and
354347
result.getControlFlowNode() = cfn
355348
}
356349

@@ -416,7 +409,7 @@ module Ssa {
416409
}
417410

418411
/**
419-
* DEPRECATED: Use `isLiveOutRefParameterDefinition(SsaDefinition, Parameter)` instead.
412+
* DEPRECATED.
420413
*
421414
* Holds if this SSA definition assigns to `out`/`ref` parameter `p`, and the
422415
* parameter may remain unchanged throughout the rest of the enclosing callable.

csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowPrivate.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1605,7 +1605,7 @@ private module ReturnNodes {
16051605

16061606
OutRefReturnNode() {
16071607
exists(Parameter p |
1608-
Ssa::isLiveOutRefParameterDefinition(this.getDefinition(), p) and
1608+
SsaImpl::isLiveOutRefParameterDefinition(this.getDefinition(), p) and
16091609
kind.getPosition() = p.getPosition()
16101610
|
16111611
p.isOut() and kind instanceof OutReturnKind

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -854,12 +854,14 @@ private module Cached {
854854
}
855855

856856
/**
857-
* Holds if the value defined at SSA definition `def` can reach a read at `cfn`,
857+
* Holds if the value defined at SSA definition `def` can reach a read `read`,
858858
* without passing through any other read.
859859
*/
860860
cached
861-
predicate firstReadSameVar(Definition def, ControlFlowNode cfn) {
862-
exists(BasicBlock bb, int i | Impl::firstUse(def, bb, i, true) and cfn = bb.getNode(i))
861+
predicate firstReadSameVar(Definition def, AssignableRead read) {
862+
exists(BasicBlock bb, int i |
863+
Impl::firstUse(def, bb, i, true) and read.getControlFlowNode() = bb.getNode(i)
864+
)
863865
}
864866

865867
/**

csharp/ql/test/library-tests/dataflow/callablereturnsarg/Common.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import csharp
22
private import semmle.code.csharp.controlflow.Guards
3+
private import semmle.code.csharp.dataflow.internal.SsaImpl as SsaImpl
34

45
private predicate outRefDef(DataFlow::ExprNode ne, int outRef) {
56
exists(SsaExplicitWrite def, Parameter outRefParameter |
67
outRefParameter.isOutOrRef() and
78
ne.getExpr() = def.getValue() and
8-
Ssa::isLiveOutRefParameterDefinition(def, outRefParameter) and
9+
SsaImpl::isLiveOutRefParameterDefinition(def, outRefParameter) and
910
outRef = outRefParameter.getPosition()
1011
)
1112
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import csharp
2+
private import semmle.code.csharp.dataflow.internal.SsaImpl as SsaImpl
23

34
from Ssa::SourceVariable v, SsaDefinition def
45
where
56
v = def.getSourceVariable() and
6-
Ssa::isLiveOutRefParameterDefinition(def, _)
7+
SsaImpl::isLiveOutRefParameterDefinition(def, _)
78
select v, def

0 commit comments

Comments
 (0)