Skip to content

Commit 2160910

Browse files
committed
C#: Remove splitting-awareness for read steps.
1 parent a5c8a5b commit 2160910

File tree

1 file changed

+46
-130
lines changed

1 file changed

+46
-130
lines changed

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

Lines changed: 46 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -2378,133 +2378,51 @@ predicate storeStep(Node node1, ContentSet c, Node node2) {
23782378
storeStepDelegateCall(node1, c, node2)
23792379
}
23802380

2381-
pragma[nomagic]
2382-
private predicate isAssignExprLValueDescendant(Expr e) {
2383-
e = any(AssignExpr ae).getLValue()
2384-
or
2385-
exists(Expr parent |
2386-
isAssignExprLValueDescendant(parent) and
2387-
e = parent.getAChildExpr()
2388-
)
2389-
}
2390-
2391-
private class ReadStepConfiguration extends ControlFlowReachabilityConfiguration {
2392-
ReadStepConfiguration() { this = "ReadStepConfiguration" }
2393-
2394-
override predicate candidate(
2395-
Expr e1, Expr e2, ControlFlowElement scope, boolean exactScope, boolean isSuccessor
2396-
) {
2397-
exactScope = false and
2398-
isSuccessor = true and
2399-
fieldOrPropertyRead(e1, _, e2) and
2400-
scope = e2
2401-
or
2402-
exactScope = false and
2403-
isSuccessor = true and
2404-
dynamicPropertyRead(e1, _, e2) and
2405-
scope = e2
2406-
or
2407-
exactScope = false and
2408-
isSuccessor = true and
2409-
arrayRead(e1, e2) and
2410-
scope = e2
2411-
or
2412-
exactScope = false and
2413-
e1 = e2.(AwaitExpr).getExpr() and
2414-
scope = e2 and
2415-
isSuccessor = true
2416-
or
2417-
exactScope = false and
2418-
e2 = e1.(TupleExpr).getAnArgument() and
2419-
scope = e1 and
2420-
isSuccessor = false
2421-
}
2422-
2423-
override predicate candidateDef(
2424-
Expr e, AssignableDefinition defTo, ControlFlowElement scope, boolean exactScope,
2425-
boolean isSuccessor
2426-
) {
2427-
exists(ForeachStmt fs |
2428-
e = fs.getIterableExpr() and
2429-
defTo.(AssignableDefinitions::LocalVariableDefinition).getDeclaration() =
2430-
fs.getVariableDeclExpr() and
2431-
isSuccessor = true
2432-
|
2433-
scope = fs and
2434-
exactScope = true
2435-
or
2436-
scope = fs.getIterableExpr() and
2437-
exactScope = false
2438-
or
2439-
scope = fs.getVariableDeclExpr() and
2440-
exactScope = false
2441-
)
2442-
or
2443-
scope =
2444-
any(AssignExpr ae |
2445-
ae = defTo.(AssignableDefinitions::TupleAssignmentDefinition).getAssignment() and
2446-
isAssignExprLValueDescendant(e.(TupleExpr)) and
2447-
exactScope = false and
2448-
isSuccessor = true
2449-
)
2450-
or
2451-
scope =
2452-
any(TupleExpr te |
2453-
te.getAnArgument() = defTo.(AssignableDefinitions::LocalVariableDefinition).getDeclaration() and
2454-
e = te and
2455-
exactScope = false and
2456-
isSuccessor = false
2457-
)
2458-
}
2459-
}
2460-
24612381
private predicate readContentStep(Node node1, Content c, Node node2) {
2462-
exists(ReadStepConfiguration x |
2463-
hasNodePath(x, node1, node2) and
2464-
arrayRead(node1.asExpr(), node2.asExpr()) and
2382+
arrayRead(node1.asExpr(), node2.asExpr()) and
2383+
c instanceof ElementContent
2384+
or
2385+
exists(
2386+
ForeachStmt fs, Ssa::ExplicitDefinition def,
2387+
AssignableDefinitions::LocalVariableDefinition defTo
2388+
|
2389+
node1.asExpr() = fs.getIterableExpr() and
2390+
defTo.getDeclaration() = fs.getVariableDeclExpr() and
2391+
def.getADefinition() = defTo and
2392+
node2.(SsaDefinitionNode).getDefinition() = def and
24652393
c instanceof ElementContent
2394+
)
2395+
or
2396+
node1 =
2397+
any(InstanceParameterAccessPreNode n |
2398+
n.getUnderlyingControlFlowNode() = node2.(ExprNode).getControlFlowNode() and
2399+
n.getParameter() = c.(PrimaryConstructorParameterContent).getParameter()
2400+
) and
2401+
node2.asExpr() instanceof ParameterRead
2402+
or
2403+
// node1 = (..., node2, ...)
2404+
// node1.ItemX flows to node2
2405+
exists(TupleExpr te, int i, Expr item |
2406+
te = node1.asExpr() and
2407+
not te.isConstruction() and
2408+
c.(FieldContent).getField() = te.getType().(TupleType).getElement(i).getUnboundDeclaration() and
2409+
// node1 = (..., item, ...)
2410+
te.getArgument(i) = item
2411+
|
2412+
// item = (..., ..., ...) in node1 = (..., (..., ..., ...), ...)
2413+
node2.asExpr().(TupleExpr) = item
24662414
or
2467-
exists(ForeachStmt fs, Ssa::ExplicitDefinition def |
2468-
x.hasDefPath(fs.getIterableExpr(), node1.getControlFlowNode(), def.getADefinition(),
2469-
def.getControlFlowNode()) and
2470-
node2.(SsaDefinitionNode).getDefinition() = def and
2471-
c instanceof ElementContent
2415+
// item = variable in node1 = (..., variable, ...)
2416+
exists(AssignableDefinitions::TupleAssignmentDefinition tad |
2417+
node2.(AssignableDefinitionNode).getDefinition() = tad and
2418+
tad.getLeaf() = item
24722419
)
24732420
or
2474-
node1 =
2475-
any(InstanceParameterAccessPreNode n |
2476-
n.getUnderlyingControlFlowNode() = node2.(ExprNode).getControlFlowNode() and
2477-
n.getParameter() = c.(PrimaryConstructorParameterContent).getParameter()
2478-
) and
2479-
node2.asExpr() instanceof ParameterRead
2480-
or
2481-
// node1 = (..., node2, ...)
2482-
// node1.ItemX flows to node2
2483-
exists(TupleExpr te, int i, Expr item |
2484-
te = node1.asExpr() and
2485-
not te.isConstruction() and
2486-
c.(FieldContent).getField() = te.getType().(TupleType).getElement(i).getUnboundDeclaration() and
2487-
// node1 = (..., item, ...)
2488-
te.getArgument(i) = item
2489-
|
2490-
// item = (..., ..., ...) in node1 = (..., (..., ..., ...), ...)
2491-
node2.asExpr().(TupleExpr) = item and
2492-
hasNodePath(x, node1, node2)
2493-
or
2494-
// item = variable in node1 = (..., variable, ...)
2495-
exists(AssignableDefinitions::TupleAssignmentDefinition tad |
2496-
node2.(AssignableDefinitionNode).getDefinition() = tad and
2497-
tad.getLeaf() = item and
2498-
hasNodePath(x, node1, node2)
2499-
)
2500-
or
2501-
// item = variable in node1 = (..., variable, ...) in a case/is var (..., ...)
2502-
isPatternExprDescendant(te) and
2503-
exists(AssignableDefinitions::LocalVariableDefinition lvd |
2504-
node2.(AssignableDefinitionNode).getDefinition() = lvd and
2505-
lvd.getDeclaration() = item and
2506-
hasNodePath(x, node1, node2)
2507-
)
2421+
// item = variable in node1 = (..., variable, ...) in a case/is var (..., ...)
2422+
isPatternExprDescendant(te) and
2423+
exists(AssignableDefinitions::LocalVariableDefinition lvd |
2424+
node2.(AssignableDefinitionNode).getDefinition() = lvd and
2425+
lvd.getDeclaration() = item
25082426
)
25092427
)
25102428
or
@@ -2535,14 +2453,12 @@ predicate readStep(Node node1, ContentSet c, Node node2) {
25352453
c.isSingleton(cont)
25362454
)
25372455
or
2538-
exists(ReadStepConfiguration x | hasNodePath(x, node1, node2) |
2539-
fieldOrPropertyRead(node1.asExpr(), c, node2.asExpr())
2540-
or
2541-
dynamicPropertyRead(node1.asExpr(), c, node2.asExpr())
2542-
or
2543-
node2.asExpr().(AwaitExpr).getExpr() = node1.asExpr() and
2544-
c = getResultContent()
2545-
)
2456+
fieldOrPropertyRead(node1.asExpr(), c, node2.asExpr())
2457+
or
2458+
dynamicPropertyRead(node1.asExpr(), c, node2.asExpr())
2459+
or
2460+
node2.asExpr().(AwaitExpr).getExpr() = node1.asExpr() and
2461+
c = getResultContent()
25462462
or
25472463
FlowSummaryImpl::Private::Steps::summaryReadStep(node1.(FlowSummaryNode).getSummaryNode(), c,
25482464
node2.(FlowSummaryNode).getSummaryNode())

0 commit comments

Comments
 (0)