Skip to content

Commit 8a29e5c

Browse files
committed
C#: Remove splitting-awareness for source-to-def steps.
1 parent 2a9161b commit 8a29e5c

File tree

1 file changed

+19
-29
lines changed

1 file changed

+19
-29
lines changed

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

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ module VariableCapture {
286286
e1 = LocalFlow::getALastEvalNode(e2)
287287
or
288288
exists(Ssa::Definition def, AssignableDefinition adef |
289-
LocalFlow::defAssigns(adef, _, e1) and
289+
LocalFlow::defAssigns(adef, _, _, e1) and
290290
def.getAnUltimateDefinition().(Ssa::ExplicitDefinition).getADefinition() = adef and
291291
exists(def.getAReadAtNode(e2))
292292
)
@@ -379,7 +379,7 @@ module VariableCapture {
379379
this = def.getExpr().getAControlFlowNode()
380380
}
381381

382-
ControlFlow::Node getRhs() { LocalFlow::defAssigns(def, this, result) }
382+
ControlFlow::Node getRhs() { LocalFlow::defAssigns(def, this, _, result) }
383383

384384
CapturedVariable getVariable() { result = v }
385385
}
@@ -620,35 +620,22 @@ module LocalFlow {
620620
)
621621
)
622622
}
623+
}
623624

624-
override predicate candidateDef(
625-
Expr e, AssignableDefinition def, ControlFlowElement scope, boolean exactScope,
626-
boolean isSuccessor
627-
) {
628-
// Flow from source to definition
629-
exactScope = false and
630-
def.getSource() = e and
631-
(
632-
scope = def.getExpr() and
633-
isSuccessor = true
634-
or
635-
scope = def.(AssignableDefinitions::PatternDefinition).getMatch().(IsExpr) and
636-
isSuccessor = false
637-
or
638-
exists(Switch s |
639-
s.getACase() = def.(AssignableDefinitions::PatternDefinition).getMatch() and
640-
isSuccessor = true
641-
|
642-
scope = s.getExpr()
643-
or
644-
scope = s.getACase()
645-
)
646-
)
647-
}
625+
predicate defAssigns(
626+
AssignableDefinition def, ControlFlow::Node cfnDef, Expr value, ControlFlow::Node valueCfn
627+
) {
628+
def.getSource() = value and
629+
valueCfn = value.getControlFlowNode() and
630+
cfnDef = def.getExpr().getAControlFlowNode()
648631
}
649632

650-
predicate defAssigns(AssignableDefinition def, ControlFlow::Node cfnDef, ControlFlow::Node value) {
651-
any(LocalExprStepConfiguration x).hasDefPath(_, value, def, cfnDef)
633+
private predicate defAssigns(ExprNode value, AssignableDefinitionNode defNode) {
634+
exists(ControlFlow::Node cfn, AssignableDefinition def, ControlFlow::Node cfnDef |
635+
defAssigns(def, cfnDef, value.getExpr(), _) and
636+
cfn = value.getControlFlowNode() and
637+
defNode = TAssignableDefinitionNode(def, cfnDef)
638+
)
652639
}
653640

654641
/**
@@ -661,6 +648,8 @@ module LocalFlow {
661648
predicate localFlowStepCommon(Node nodeFrom, Node nodeTo) {
662649
hasNodePath(any(LocalExprStepConfiguration x), nodeFrom, nodeTo)
663650
or
651+
defAssigns(nodeFrom, nodeTo)
652+
or
664653
ThisFlow::adjacentThisRefs(nodeFrom, nodeTo) and
665654
nodeFrom != nodeTo
666655
or
@@ -729,9 +718,10 @@ module LocalFlow {
729718
e instanceof ThisAccess or e instanceof BaseAccess
730719
)
731720
or
721+
defAssigns(node1, node2)
722+
or
732723
hasNodePath(any(LocalExprStepConfiguration x), node1, node2) and
733724
(
734-
node2 instanceof AssignableDefinitionNode or
735725
node2.asExpr() instanceof Cast or
736726
node2.asExpr() instanceof AssignExpr
737727
)

0 commit comments

Comments
 (0)