Skip to content

Commit 6918dad

Browse files
committed
C#: Refactor localFlowStep()
Using the `forceCachingInSameStage()` trick, we can get rid of the non-cached version of local flow, while still computing it in the same stage.
1 parent 1366638 commit 6918dad

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

csharp/ql/src/semmle/code/csharp/dataflow/DataFlow.qll

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ module DataFlow {
9090
localFlowStep*(source, sink)
9191
}
9292

93-
predicate localFlowStep = localFlowStepCached/2;
93+
predicate localFlowStep = Internal::LocalFlow::step/2;
9494

9595
/**
9696
* A data flow node augmented with a call context and a configuration. Only
@@ -690,12 +690,14 @@ module DataFlow {
690690
/**
691691
* Provides predicates related to local data flow.
692692
*/
693-
private module LocalFlow {
693+
module LocalFlow {
694694
/**
695695
* Holds if data flows from `nodeFrom` to `nodeTo` in exactly one local
696696
* (intra-procedural) step.
697697
*/
698-
predicate localFlowStepNonCached(Node nodeFrom, Node nodeTo) {
698+
cached
699+
predicate step(Node nodeFrom, Node nodeTo) {
700+
forceCachingInSameStage() and
699701
localFlowStepExpr(nodeFrom.asExpr(), nodeTo.asExpr())
700702
or
701703
// Flow from source to SSA definition
@@ -1119,6 +1121,8 @@ module DataFlow {
11191121
* same stage.
11201122
*/
11211123
cached module Cached {
1124+
cached predicate forceCachingInSameStage() { any() }
1125+
11221126
cached newtype TNode =
11231127
TExprNode(DotNet::Expr e)
11241128
or
@@ -1137,14 +1141,6 @@ module DataFlow {
11371141
)
11381142
}
11391143

1140-
/**
1141-
* Holds if data flows from `nodeFrom` to `nodeTo` in exactly one local
1142-
* (intra-procedural) step.
1143-
*/
1144-
cached predicate localFlowStepCached(Node nodeFrom, Node nodeTo) {
1145-
LocalFlow::localFlowStepNonCached(nodeFrom, nodeTo)
1146-
}
1147-
11481144
/**
11491145
* Holds if `pred` can flow to `succ`, by jumping from one callable to
11501146
* another.

0 commit comments

Comments
 (0)