Skip to content

Commit 13c109c

Browse files
committed
C#: Unmerge SSA and data flow stages
1 parent 6c16b8a commit 13c109c

File tree

2 files changed

+34
-20
lines changed

2 files changed

+34
-20
lines changed

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ module VariableCapture {
484484

485485
/** Provides logic related to SSA. */
486486
module SsaFlow {
487-
module Impl = SsaImpl::DataFlowIntegration;
487+
private module Impl = SsaImpl::DataFlowIntegration;
488488

489489
Impl::Node asNode(Node n) {
490490
n = TSsaNode(result)
@@ -497,8 +497,8 @@ module SsaFlow {
497497
TExplicitParameterNode(result.(Impl::ParameterNode).getParameter()) = n
498498
}
499499

500-
predicate localFlowStep(SsaImpl::DefinitionExt def, Node nodeFrom, Node nodeTo) {
501-
Impl::localFlowStep(def, asNode(nodeFrom), asNode(nodeTo))
500+
predicate localFlowStep(SsaImpl::DefinitionExt def, Node nodeFrom, Node nodeTo, boolean isUseStep) {
501+
Impl::localFlowStep(def, asNode(nodeFrom), asNode(nodeTo), isUseStep)
502502
}
503503

504504
predicate localMustFlowStep(SsaImpl::DefinitionExt def, Node nodeFrom, Node nodeTo) {
@@ -738,10 +738,13 @@ predicate simpleLocalFlowStep(Node nodeFrom, Node nodeTo, string model) {
738738
(
739739
LocalFlow::localFlowStepCommon(nodeFrom, nodeTo)
740740
or
741-
exists(SsaImpl::DefinitionExt def |
742-
SsaFlow::localFlowStep(def, nodeFrom, nodeTo) and
741+
exists(SsaImpl::DefinitionExt def, boolean isUseStep |
742+
SsaFlow::localFlowStep(def, nodeFrom, nodeTo, isUseStep) and
743743
not LocalFlow::usesInstanceField(def) and
744-
not def instanceof VariableCapture::CapturedSsaDefinitionExt and
744+
not def instanceof VariableCapture::CapturedSsaDefinitionExt
745+
|
746+
isUseStep = false
747+
or
745748
not FlowSummaryImpl::Private::Steps::prohibitsUseUseFlow(nodeFrom, _)
746749
)
747750
or
@@ -1008,7 +1011,7 @@ private module Cached {
10081011
cached
10091012
newtype TNode =
10101013
TExprNode(ControlFlow::Nodes::ElementNode cfn) { cfn.getAstNode() instanceof Expr } or
1011-
TSsaNode(SsaFlow::Impl::SsaNode node) or
1014+
TSsaNode(SsaImpl::DataFlowIntegration::SsaNode node) or
10121015
TAssignableDefinitionNode(AssignableDefinition def, ControlFlow::Node cfn) {
10131016
cfn = def.getExpr().getAControlFlowNode()
10141017
} or
@@ -1073,7 +1076,7 @@ private module Cached {
10731076
predicate localFlowStepImpl(Node nodeFrom, Node nodeTo) {
10741077
LocalFlow::localFlowStepCommon(nodeFrom, nodeTo)
10751078
or
1076-
SsaFlow::localFlowStep(_, nodeFrom, nodeTo)
1079+
SsaFlow::localFlowStep(_, nodeFrom, nodeTo, _)
10771080
or
10781081
// Simple flow through library code is included in the exposed local
10791082
// step relation, even though flow is technically inter-procedural
@@ -1178,7 +1181,7 @@ predicate nodeIsHidden(Node n) {
11781181

11791182
/** An SSA node. */
11801183
abstract class SsaNode extends NodeImpl, TSsaNode {
1181-
SsaFlow::Impl::SsaNode node;
1184+
SsaImpl::DataFlowIntegration::SsaNode node;
11821185
SsaImpl::DefinitionExt def;
11831186

11841187
SsaNode() {
@@ -1205,7 +1208,7 @@ abstract class SsaNode extends NodeImpl, TSsaNode {
12051208

12061209
/** An (extended) SSA definition, viewed as a node in a data flow graph. */
12071210
class SsaDefinitionExtNode extends SsaNode {
1208-
override SsaFlow::Impl::SsaDefinitionExtNode node;
1211+
override SsaImpl::DataFlowIntegration::SsaDefinitionExtNode node;
12091212
}
12101213

12111214
/**
@@ -1248,7 +1251,7 @@ class SsaDefinitionExtNode extends SsaNode {
12481251
* both inputs into the phi read node after the outer condition are guarded.
12491252
*/
12501253
class SsaInputNode extends SsaNode {
1251-
override SsaFlow::Impl::SsaInputNode node;
1254+
override SsaImpl::DataFlowIntegration::SsaInputNode node;
12521255
}
12531256

12541257
/** A definition, viewed as a node in a data flow graph. */
@@ -2798,7 +2801,7 @@ private predicate delegateCreationStep(Node nodeFrom, Node nodeTo) {
27982801
/** Extra data-flow steps needed for lambda flow analysis. */
27992802
predicate additionalLambdaFlowStep(Node nodeFrom, Node nodeTo, boolean preservesValue) {
28002803
exists(SsaImpl::DefinitionExt def |
2801-
SsaFlow::localFlowStep(def, nodeFrom, nodeTo) and
2804+
SsaFlow::localFlowStep(def, nodeFrom, nodeTo, _) and
28022805
preservesValue = true
28032806
|
28042807
LocalFlow::usesInstanceField(def)

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

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import csharp
66
private import codeql.ssa.Ssa as SsaImplCommon
77
private import AssignableDefinitions
88
private import semmle.code.csharp.controlflow.internal.PreSsa
9+
private import semmle.code.csharp.controlflow.Guards as Guards
910

1011
private module SsaInput implements SsaImplCommon::InputSig<Location> {
1112
class BasicBlock = ControlFlow::BasicBlock;
@@ -978,13 +979,24 @@ private module Cached {
978979
)
979980
}
980981

981-
private import TaintTrackingPrivate as TaintTrackingPrivate
982-
983982
cached
984-
predicate forceCachingInSameStage() {
985-
// needed in order to avoid recomputing SSA predicates in the `Integration` module
986-
TaintTrackingPrivate::forceCachingInSameStage() and
987-
DataFlowIntegration::localFlowStep(_, _, _)
983+
module DataFlowIntegration {
984+
import DataFlowIntegrationImpl
985+
986+
cached
987+
predicate localFlowStep(DefinitionExt def, Node nodeFrom, Node nodeTo, boolean isUseStep) {
988+
DataFlowIntegrationImpl::localFlowStep(def, nodeFrom, nodeTo, isUseStep)
989+
}
990+
991+
cached
992+
predicate localMustFlowStep(DefinitionExt def, Node nodeFrom, Node nodeTo) {
993+
DataFlowIntegrationImpl::localMustFlowStep(def, nodeFrom, nodeTo)
994+
}
995+
996+
cached
997+
Node getABarrierNode(Guards::Guard guard, Ssa::Definition def, boolean branch) {
998+
result = DataFlowIntegrationImpl::getABarrierNode(guard, def, branch)
999+
}
9881000
}
9891001
}
9901002

@@ -1047,7 +1059,6 @@ class PhiReadNode extends DefinitionExt, Impl::PhiReadNode {
10471059
private module DataFlowIntegrationInput implements Impl::DataFlowIntegrationInputSig {
10481060
private import csharp as Cs
10491061
private import semmle.code.csharp.controlflow.BasicBlocks
1050-
private import semmle.code.csharp.controlflow.Guards as Guards
10511062

10521063
class Expr extends ControlFlow::Node {
10531064
predicate hasCfgNode(ControlFlow::BasicBlock bb, int i) { this = bb.getNode(i) }
@@ -1104,4 +1115,4 @@ private module DataFlowIntegrationInput implements Impl::DataFlowIntegrationInpu
11041115
}
11051116
}
11061117

1107-
module DataFlowIntegration = Impl::DataFlowIntegration<DataFlowIntegrationInput>;
1118+
private module DataFlowIntegrationImpl = Impl::DataFlowIntegration<DataFlowIntegrationInput>;

0 commit comments

Comments
 (0)