Skip to content

Commit f48f2ea

Browse files
committed
C#: Include "phi reads" in DataFlow::Node
1 parent 7a8c9e7 commit f48f2ea

10 files changed

Lines changed: 544 additions & 240 deletions

File tree

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

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -138,25 +138,6 @@ module Ssa {
138138
}
139139
}
140140

141-
private string getSplitString(Definition def) {
142-
exists(ControlFlow::BasicBlock bb, int i, ControlFlow::Node cfn |
143-
def.definesAt(_, bb, i) and
144-
result = cfn.(ControlFlow::Nodes::ElementNode).getSplitsString()
145-
|
146-
cfn = bb.getNode(i)
147-
or
148-
not exists(bb.getNode(i)) and
149-
cfn = bb.getFirstNode()
150-
)
151-
}
152-
153-
private string getToStringPrefix(Definition def) {
154-
result = "[" + getSplitString(def) + "] "
155-
or
156-
not exists(getSplitString(def)) and
157-
result = ""
158-
}
159-
160141
/**
161142
* A static single assignment (SSA) definition. Either an explicit variable
162143
* definition (`ExplicitDefinition`), an implicit variable definition
@@ -521,8 +502,8 @@ module Ssa {
521502

522503
override string toString() {
523504
if this.getADefinition() instanceof AssignableDefinitions::ImplicitParameterDefinition
524-
then result = getToStringPrefix(this) + "SSA param(" + this.getSourceVariable() + ")"
525-
else result = getToStringPrefix(this) + "SSA def(" + this.getSourceVariable() + ")"
505+
then result = SsaImpl::getToStringPrefix(this) + "SSA param(" + this.getSourceVariable() + ")"
506+
else result = SsaImpl::getToStringPrefix(this) + "SSA def(" + this.getSourceVariable() + ")"
526507
}
527508

528509
override Location getLocation() { result = ad.getLocation() }
@@ -570,8 +551,12 @@ module Ssa {
570551

571552
override string toString() {
572553
if this.getSourceVariable().getAssignable() instanceof LocalScopeVariable
573-
then result = getToStringPrefix(this) + "SSA capture def(" + this.getSourceVariable() + ")"
574-
else result = getToStringPrefix(this) + "SSA entry def(" + this.getSourceVariable() + ")"
554+
then
555+
result =
556+
SsaImpl::getToStringPrefix(this) + "SSA capture def(" + this.getSourceVariable() + ")"
557+
else
558+
result =
559+
SsaImpl::getToStringPrefix(this) + "SSA entry def(" + this.getSourceVariable() + ")"
575560
}
576561

577562
override Location getLocation() { result = this.getCallable().getLocation() }
@@ -612,7 +597,7 @@ module Ssa {
612597
}
613598

614599
override string toString() {
615-
result = getToStringPrefix(this) + "SSA call def(" + this.getSourceVariable() + ")"
600+
result = SsaImpl::getToStringPrefix(this) + "SSA call def(" + this.getSourceVariable() + ")"
616601
}
617602

618603
override Location getLocation() { result = this.getCall().getLocation() }
@@ -640,7 +625,8 @@ module Ssa {
640625
final Definition getQualifierDefinition() { result = q }
641626

642627
override string toString() {
643-
result = getToStringPrefix(this) + "SSA qualifier def(" + this.getSourceVariable() + ")"
628+
result =
629+
SsaImpl::getToStringPrefix(this) + "SSA qualifier def(" + this.getSourceVariable() + ")"
644630
}
645631

646632
override Location getLocation() { result = this.getQualifierDefinition().getLocation() }
@@ -682,7 +668,7 @@ module Ssa {
682668
}
683669

684670
override string toString() {
685-
result = getToStringPrefix(this) + "SSA phi(" + this.getSourceVariable() + ")"
671+
result = SsaImpl::getToStringPrefix(this) + "SSA phi(" + this.getSourceVariable() + ")"
686672
}
687673

688674
/*

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,14 @@ private module Cached {
402402
)
403403
}
404404

405+
private Node testviableCallableLambda(DataFlowCall call, DataFlowCallOption lastCall) {
406+
exists(LambdaCallKind kind |
407+
LambdaFlow::revLambdaFlow(call, kind, result, _, _, _, lastCall) and
408+
// lambdaCreation(creation, kind, result) and
409+
call.getLocation().getStartLine() = 575
410+
)
411+
}
412+
405413
/**
406414
* Holds if `p` is the parameter of a viable dispatch target of `call`,
407415
* and `p` has position `ppos`.

0 commit comments

Comments
 (0)