Skip to content

Commit 1e8de05

Browse files
committed
C#: Remove splitting-awareness in lambda flow.
1 parent bce0a4d commit 1e8de05

File tree

1 file changed

+15
-34
lines changed

1 file changed

+15
-34
lines changed

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

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,7 @@ private module Cached {
11541154
)
11551155
)
11561156
or
1157-
lambdaCallExpr(_, cfn)
1157+
lambdaCallExpr(_, _, cfn)
11581158
} or
11591159
TFlowSummaryNode(FlowSummaryImpl::Private::SummaryNode sn) {
11601160
sn.getSummarizedCallable() instanceof CallableUsedInSource
@@ -1588,7 +1588,7 @@ private module ArgumentNodes {
15881588
class DelegateSelfArgumentNode extends ArgumentNodeImpl, ExprNode {
15891589
private DataFlowCall call_;
15901590

1591-
DelegateSelfArgumentNode() { lambdaCallExpr(call_, this.getControlFlowNode()) }
1591+
DelegateSelfArgumentNode() { lambdaCallExpr(call_, this.getExpr(), _) }
15921592

15931593
override predicate argumentOf(DataFlowCall call, ArgumentPosition pos) {
15941594
call = call_ and
@@ -2855,45 +2855,26 @@ private predicate isLocalFunctionCallReceiver(
28552855
f = receiver.getTarget().getUnboundDeclaration()
28562856
}
28572857

2858-
private class LambdaConfiguration extends ControlFlowReachabilityConfiguration {
2859-
LambdaConfiguration() { this = "LambdaConfiguration" }
2860-
2861-
override predicate candidate(
2862-
Expr e1, Expr e2, ControlFlowElement scope, boolean exactScope, boolean isSuccessor
2863-
) {
2864-
e1 = e2.(DelegateLikeCall).getExpr() and
2865-
exactScope = false and
2866-
scope = e2 and
2867-
isSuccessor = true
2868-
or
2869-
e1 = e2.(DelegateCreation).getArgument() and
2870-
exactScope = false and
2871-
scope = e2 and
2872-
isSuccessor = true
2873-
or
2874-
isLocalFunctionCallReceiver(e2, e1, _) and
2875-
exactScope = false and
2876-
scope = e2 and
2877-
isSuccessor = true
2878-
}
2879-
}
2880-
2881-
private predicate lambdaCallExpr(DataFlowCall call, ControlFlow::Node receiver) {
2882-
exists(LambdaConfiguration x, DelegateLikeCall dc |
2883-
x.hasExprPath(dc.getExpr(), receiver, dc, call.getControlFlowNode())
2858+
private predicate lambdaCallExpr(DataFlowCall call, Expr receiver, ControlFlow::Node receiverCfn) {
2859+
exists(DelegateLikeCall dc |
2860+
call.(ExplicitDelegateLikeDataFlowCall).getCall() = dc and
2861+
receiver = dc.getExpr() and
2862+
receiverCfn = receiver.getControlFlowNode()
28842863
)
28852864
or
28862865
// In local function calls, `F()`, we use the local function access `F`
28872866
// to represent the receiver. Only needed for flow through captured variables.
2888-
exists(LambdaConfiguration x, LocalFunctionCall fc |
2889-
x.hasExprPath(fc.getAChild(), receiver, fc, call.getControlFlowNode())
2867+
exists(LocalFunctionCall fc |
2868+
receiver = fc.getAChild() and
2869+
receiverCfn = receiver.getControlFlowNode() and
2870+
fc.getControlFlowNode() = call.getControlFlowNode()
28902871
)
28912872
}
28922873

28932874
/** Holds if `call` is a lambda call where `receiver` is the lambda expression. */
28942875
predicate lambdaCall(DataFlowCall call, LambdaCallKind kind, Node receiver) {
28952876
(
2896-
lambdaCallExpr(call, receiver.(ExprNode).getControlFlowNode()) and
2877+
lambdaCallExpr(call, receiver.asExpr(), _) and
28972878
// local function calls can be resolved directly without a flow analysis
28982879
not call.getControlFlowNode().getAstNode() instanceof LocalFunctionCall
28992880
or
@@ -2903,9 +2884,9 @@ predicate lambdaCall(DataFlowCall call, LambdaCallKind kind, Node receiver) {
29032884
}
29042885

29052886
private predicate delegateCreationStep(Node nodeFrom, Node nodeTo) {
2906-
exists(LambdaConfiguration x, DelegateCreation dc |
2907-
x.hasExprPath(dc.getArgument(), nodeFrom.(ExprNode).getControlFlowNode(), dc,
2908-
nodeTo.(ExprNode).getControlFlowNode())
2887+
exists(DelegateCreation dc |
2888+
dc.getArgument() = nodeFrom.asExpr() and
2889+
dc = nodeTo.asExpr()
29092890
)
29102891
}
29112892

0 commit comments

Comments
 (0)