Skip to content

Commit b05199d

Browse files
committed
Tuple data flow: take cfg reachability into account
1 parent 0ca4bf4 commit b05199d

File tree

1 file changed

+32
-21
lines changed

1 file changed

+32
-21
lines changed

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

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -804,27 +804,28 @@ private module Cached {
804804
hasNodePath(x, node1, node2) and
805805
node2.asExpr().(AwaitExpr).getExpr() = node1.asExpr() and
806806
c = getResultContent()
807-
)
808-
or
809-
// node1 = (..., node2, ...)
810-
// node1.ItemX flows to node2
811-
exists(
812-
int i, Ssa::ExplicitDefinition def, AssignableDefinitions::TupleAssignmentDefinition tad,
813-
Expr item
814-
|
815-
// node1 = (..., item, ...)
816-
node1.asExpr().(TupleExpr).getArgument(i) = item and
817-
(
818-
// item = (..., ..., ...) in node1 = (..., (..., ..., ...), ...)
819-
node2.asExpr() instanceof TupleExpr and node2.asExpr() = item
820-
or
821-
// item = variable in node1 = (..., variable, ...)
822-
node2.(SsaDefinitionNode).getDefinition() = def and
823-
def.getADefinition() = tad and
824-
tad.getLeaf() = item
825-
) and
826-
c.(FieldContent).getField() =
827-
node1.asExpr().getType().(TupleType).getElement(i).getUnboundDeclaration()
807+
or
808+
// node1 = (..., node2, ...)
809+
// node1.ItemX flows to node2
810+
exists(
811+
int i, Ssa::ExplicitDefinition def, AssignableDefinitions::TupleAssignmentDefinition tad,
812+
Expr item
813+
|
814+
// node1 = (..., item, ...)
815+
node1.asExpr().(TupleExpr).getArgument(i) = item and
816+
(
817+
// item = (..., ..., ...) in node1 = (..., (..., ..., ...), ...)
818+
node2.asExpr().(TupleExpr) = item and hasNodePath(x, node2, node1)
819+
or
820+
// item = variable in node1 = (..., variable, ...)
821+
node2.(SsaDefinitionNode).getDefinition() = def and
822+
def.getADefinition() = tad and
823+
tad.getLeaf() = item and
824+
hasNodePath(x, node1, any(Node n | n.asExpr() = tad.getAssignment()))
825+
) and
826+
c.(FieldContent).getField() =
827+
node1.asExpr().getType().(TupleType).getElement(i).getUnboundDeclaration()
828+
)
828829
)
829830
or
830831
FlowSummaryImpl::Private::readStep(node1, c, node2)
@@ -1764,6 +1765,16 @@ private class ReadStepConfiguration extends ControlFlowReachabilityConfiguration
17641765
e1 = e2.(AwaitExpr).getExpr() and
17651766
scope = e2 and
17661767
isSuccessor = true
1768+
or
1769+
exactScope = false and
1770+
e1 = e2.(TupleExpr).getAnArgument() and
1771+
scope = e2 and
1772+
isSuccessor = true
1773+
or
1774+
exactScope = false and
1775+
e1.(TupleExpr).getParent*() = e2.(AssignExpr).getLValue() and
1776+
scope = e2 and
1777+
isSuccessor = true
17671778
}
17681779

17691780
override predicate candidateDef(

0 commit comments

Comments
 (0)