Skip to content

Commit 346af4f

Browse files
committed
Data flow: Cache ReturnNodeExt
1 parent 9738de2 commit 346af4f

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

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

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,17 @@ private module Cached {
279279
)
280280
}
281281

282+
cached
283+
predicate returnNodeExt(Node n, ReturnKindExt k) {
284+
k = TValueReturn(n.(ReturnNode).getKind())
285+
or
286+
exists(ParameterNode p, int pos |
287+
parameterValueFlowsToPreUpdate(p, n) and
288+
p.isParameterOf(_, pos) and
289+
k = TParamUpdate(pos)
290+
)
291+
}
292+
282293
/**
283294
* Gets a viable target for the lambda call `call`.
284295
*
@@ -672,8 +683,7 @@ private module Cached {
672683
* Holds if `p` can flow to the pre-update node associated with post-update
673684
* node `n`, in the same callable, using only value-preserving steps.
674685
*/
675-
cached
676-
predicate parameterValueFlowsToPreUpdate(ParameterNode p, PostUpdateNode n) {
686+
private predicate parameterValueFlowsToPreUpdate(ParameterNode p, PostUpdateNode n) {
677687
parameterValueFlow(p, n.getPreUpdateNode(), TReadStepTypesNone())
678688
}
679689

@@ -965,21 +975,10 @@ LocalCallContext getLocalCallContext(CallContext ctx, DataFlowCallable callable)
965975
* `ReturnNode` or a `PostUpdateNode` corresponding to the value of a parameter.
966976
*/
967977
class ReturnNodeExt extends Node {
968-
ReturnNodeExt() {
969-
this instanceof ReturnNode or
970-
parameterValueFlowsToPreUpdate(_, this)
971-
}
978+
ReturnNodeExt() { returnNodeExt(this, _) }
972979

973980
/** Gets the kind of this returned value. */
974-
ReturnKindExt getKind() {
975-
result = TValueReturn(this.(ReturnNode).getKind())
976-
or
977-
exists(ParameterNode p, int pos |
978-
parameterValueFlowsToPreUpdate(p, this) and
979-
p.isParameterOf(_, pos) and
980-
result = TParamUpdate(pos)
981-
)
982-
}
981+
ReturnKindExt getKind() { returnNodeExt(this, result) }
983982
}
984983

985984
/**

0 commit comments

Comments
 (0)