Skip to content

Commit bce0a4d

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

File tree

1 file changed

+30
-71
lines changed

1 file changed

+30
-71
lines changed

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

Lines changed: 30 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -834,11 +834,11 @@ private class Argument extends Expr {
834834
}
835835

836836
/**
837-
* Holds if `e` is an assignment of `src` to field or property `c` of `q`.
837+
* Holds if there is an assignment of `src` to field or property `c` of `q`.
838838
*
839839
* `postUpdate` indicates whether the store targets a post-update node.
840840
*/
841-
private predicate fieldOrPropertyStore(Expr e, ContentSet c, Expr src, Expr q, boolean postUpdate) {
841+
private predicate fieldOrPropertyStore(ContentSet c, Expr src, Expr q, boolean postUpdate) {
842842
exists(FieldOrProperty f |
843843
c = f.getContentSet() and
844844
(
@@ -861,25 +861,20 @@ private predicate fieldOrPropertyStore(Expr e, ContentSet c, Expr src, Expr q, b
861861
f = fa.getTarget() and
862862
src = def.getSource() and
863863
q = fa.getQualifier() and
864-
e = def.getExpr() and
865864
postUpdate = true
866865
)
867866
or
868867
// `with` expression initializer, `x with { f = src }`
869-
e =
870-
any(WithExpr we |
871-
exists(MemberInitializer mi |
872-
q = we and
873-
mi = we.getInitializer().getAMemberInitializer() and
874-
f = mi.getInitializedMember() and
875-
src = mi.getRValue() and
876-
postUpdate = false
877-
)
878-
)
868+
exists(WithExpr we, MemberInitializer mi |
869+
q = we and
870+
mi = we.getInitializer().getAMemberInitializer() and
871+
f = mi.getInitializedMember() and
872+
src = mi.getRValue() and
873+
postUpdate = false
874+
)
879875
or
880876
// Object initializer, `new C() { f = src }`
881877
exists(MemberInitializer mi |
882-
e = q and
883878
mi = q.(ObjectInitializer).getAMemberInitializer() and
884879
q.getParent() instanceof ObjectCreation and
885880
f = mi.getInitializedMember() and
@@ -888,16 +883,13 @@ private predicate fieldOrPropertyStore(Expr e, ContentSet c, Expr src, Expr q, b
888883
)
889884
or
890885
// Tuple element, `(..., src, ...)` `f` is `ItemX` of tuple `q`
891-
e =
892-
any(TupleExpr te |
893-
exists(int i |
894-
e = q and
895-
src = te.getArgument(i) and
896-
te.isConstruction() and
897-
f = q.getType().(TupleType).getElement(i) and
898-
postUpdate = false
899-
)
900-
)
886+
exists(TupleExpr te, int i |
887+
te = q and
888+
src = te.getArgument(i) and
889+
te.isConstruction() and
890+
f = q.getType().(TupleType).getElement(i) and
891+
postUpdate = false
892+
)
901893
)
902894
or
903895
// A write to a dynamic property
@@ -907,7 +899,6 @@ private predicate fieldOrPropertyStore(Expr e, ContentSet c, Expr src, Expr q, b
907899
c.isDynamicProperty(dp) and
908900
src = def.getSource() and
909901
q = dma.getQualifier() and
910-
e = def.getExpr() and
911902
postUpdate = true
912903
)
913904
}
@@ -943,30 +934,27 @@ private predicate collectionStore(Expr src, CollectionExpression ce) {
943934
}
944935

945936
/**
946-
* Holds if `e` is an expression that adds `src` to array `a`.
937+
* Holds if there is an expression that adds `src` to array `a`.
947938
*
948939
* `postUpdate` indicates whether the store targets a post-update node.
949940
*/
950-
private predicate arrayStore(Expr e, Expr src, Expr a, boolean postUpdate) {
941+
private predicate arrayStore(Expr src, Expr a, boolean postUpdate) {
951942
// Direct assignment, `a[i] = src`
952943
exists(AssignableDefinition def |
953944
a = def.getTargetAccess().(ArrayWrite).getQualifier() and
954945
src = def.getSource() and
955-
e = def.getExpr() and
956946
postUpdate = true
957947
)
958948
or
959949
// Array initializer, `new [] { src }`
960950
src = a.(ArrayInitializer).getAnElement() and
961-
e = a and
962951
postUpdate = false
963952
or
964953
// Member initializer, `new C { Array = { [i] = src } }`
965954
exists(MemberInitializer mi |
966955
mi = a.(ObjectInitializer).getAMemberInitializer() and
967956
mi.getLValue() instanceof ArrayAccess and
968957
mi.getRValue() = src and
969-
e = a and
970958
postUpdate = false
971959
)
972960
}
@@ -1149,9 +1137,9 @@ private module Cached {
11491137
exprMayHavePostUpdateNode(cfn.getExpr())
11501138
or
11511139
exists(Expr e | e = cfn.getExpr() |
1152-
fieldOrPropertyStore(_, _, _, e, true)
1140+
fieldOrPropertyStore(_, _, e, true)
11531141
or
1154-
arrayStore(_, _, e, true)
1142+
arrayStore(_, e, true)
11551143
or
11561144
// needed for reverse stores; e.g. `x.f1.f2 = y` induces
11571145
// a store step of `f1` into `x`
@@ -2236,30 +2224,6 @@ predicate jumpStep(Node pred, Node succ) {
22362224
succ = pred.(LocalFunctionCreationNode).getAnAccess(false)
22372225
}
22382226

2239-
private class StoreStepConfiguration extends ControlFlowReachabilityConfiguration {
2240-
StoreStepConfiguration() { this = "StoreStepConfiguration" }
2241-
2242-
override predicate candidate(
2243-
Expr e1, Expr e2, ControlFlowElement scope, boolean exactScope, boolean isSuccessor
2244-
) {
2245-
exactScope = false and
2246-
fieldOrPropertyStore(scope, _, e1, e2, isSuccessor.booleanNot())
2247-
or
2248-
exactScope = false and
2249-
arrayStore(scope, e1, e2, isSuccessor.booleanNot())
2250-
or
2251-
exactScope = false and
2252-
isSuccessor = true and
2253-
collectionStore(e1, e2) and
2254-
scope = e2
2255-
or
2256-
exactScope = false and
2257-
isSuccessor = true and
2258-
isParamsArg(e2, e1, _) and
2259-
scope = e2
2260-
}
2261-
}
2262-
22632227
pragma[nomagic]
22642228
private ContentSet getResultContent() {
22652229
result.isProperty(any(SystemThreadingTasksTaskTClass c_).getResultProperty())
@@ -2282,21 +2246,17 @@ private predicate recordParameter(RecordType t, Parameter p, string name) {
22822246
}
22832247

22842248
private predicate storeContentStep(Node node1, Content c, Node node2) {
2285-
exists(StoreStepConfiguration x, ExprNode node, boolean postUpdate |
2286-
hasNodePath(x, node1, node) and
2249+
exists(ExprNode node, boolean postUpdate |
22872250
if postUpdate = true then node = node2.(PostUpdateNode).getPreUpdateNode() else node = node2
22882251
|
2289-
arrayStore(_, node1.asExpr(), node.getExpr(), postUpdate) and c instanceof ElementContent
2252+
arrayStore(node1.asExpr(), node.getExpr(), postUpdate) and c instanceof ElementContent
22902253
)
22912254
or
2292-
exists(StoreStepConfiguration x | hasNodePath(x, node1, node2) |
2293-
collectionStore(node1.asExpr(), node2.asExpr()) and c instanceof ElementContent
2294-
)
2255+
collectionStore(node1.asExpr(), node2.asExpr()) and c instanceof ElementContent
22952256
or
2296-
exists(StoreStepConfiguration x, Expr arg, ControlFlow::Node callCfn |
2297-
x.hasExprPath(arg, node1.(ExprNode).getControlFlowNode(), _, callCfn) and
2298-
node2 = TParamsArgumentNode(callCfn) and
2299-
isParamsArg(_, arg, _) and
2257+
exists(Call call |
2258+
node2 = TParamsArgumentNode(call.getControlFlowNode()) and
2259+
isParamsArg(call, node1.asExpr(), _) and
23002260
c instanceof ElementContent
23012261
)
23022262
or
@@ -2352,11 +2312,10 @@ predicate storeStep(Node node1, ContentSet c, Node node2) {
23522312
c.isSingleton(cont)
23532313
)
23542314
or
2355-
exists(StoreStepConfiguration x, ExprNode node, boolean postUpdate |
2356-
hasNodePath(x, node1, node) and
2315+
exists(ExprNode node, boolean postUpdate |
23572316
if postUpdate = true then node = node2.(PostUpdateNode).getPreUpdateNode() else node = node2
23582317
|
2359-
fieldOrPropertyStore(_, c, node1.asExpr(), node.getExpr(), postUpdate)
2318+
fieldOrPropertyStore(c, node1.asExpr(), node.getExpr(), postUpdate)
23602319
)
23612320
or
23622321
exists(Expr e |
@@ -2492,9 +2451,9 @@ predicate clearsContent(Node n, ContentSet c) {
24922451
c.isSingleton(cont)
24932452
)
24942453
or
2495-
fieldOrPropertyStore(_, c, _, n.asExpr(), true)
2454+
fieldOrPropertyStore(c, _, n.asExpr(), true)
24962455
or
2497-
fieldOrPropertyStore(_, c, _, n.(ObjectInitializerNode).getInitializer(), false)
2456+
fieldOrPropertyStore(c, _, n.(ObjectInitializerNode).getInitializer(), false)
24982457
or
24992458
FlowSummaryImpl::Private::Steps::summaryClearsContent(n.(FlowSummaryNode).getSummaryNode(), c)
25002459
or

0 commit comments

Comments
 (0)