Skip to content

Commit 2d0a377

Browse files
committed
C#: Update dataflow consistency queries to cater for non unique post and pre unique update notes for conditional branches.
1 parent e8fd2bf commit 2d0a377

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

csharp/ql/consistency-queries/DataFlowConsistency.ql

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,7 @@ private class MyConsistencyConfiguration extends ConsistencyConfiguration {
3535
override predicate argHasPostUpdateExclude(ArgumentNode n) {
3636
n instanceof SummaryNode
3737
or
38-
n.asExpr().(Expr).stripCasts().getType() =
39-
any(Type t |
40-
not t instanceof RefType and
41-
not t = any(TypeParameter tp | not tp.isValueType())
42-
or
43-
t instanceof NullType
44-
)
38+
not exists(getAPostUpdateNodeForArg(n.asExpr()))
4539
or
4640
n instanceof ImplicitCapturedArgumentNode
4741
or
@@ -50,5 +44,21 @@ private class MyConsistencyConfiguration extends ConsistencyConfiguration {
5044
n.asExpr() instanceof CIL::Expr
5145
}
5246

47+
override predicate postHasUniquePreExclude(PostUpdateNode n) {
48+
exists(ControlFlow::Nodes::ExprNode e, ControlFlow::Nodes::ExprNode arg |
49+
e = getAPostUpdateNodeForArg(arg.getExpr()) and
50+
e != arg and
51+
n = TExprPostUpdateNode(e)
52+
)
53+
}
54+
55+
override predicate uniquePostUpdateExclude(Node n) {
56+
exists(ControlFlow::Nodes::ExprNode e, ControlFlow::Nodes::ExprNode arg |
57+
e = getAPostUpdateNodeForArg(arg.getExpr()) and
58+
e != arg and
59+
n.asExpr() = arg.getExpr()
60+
)
61+
}
62+
5363
override predicate reverseReadExclude(Node n) { n.asExpr() = any(AwaitExpr ae).getExpr() }
5464
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ private predicate relevantArgumentType(ControlFlow::Nodes::ExprNode cfn) {
197197
}
198198

199199
/** Gets a node for which to construct a post-update node for argument `arg`. */
200-
private ControlFlow::Nodes::ExprNode getAPostUpdateNodeForArg(Argument arg) {
200+
ControlFlow::Nodes::ExprNode getAPostUpdateNodeForArg(Argument arg) {
201201
result = getALastEvalNode*(arg.getAControlFlowNode()) and
202202
relevantArgumentType(result) and
203203
not exists(getALastEvalNode(result))

0 commit comments

Comments
 (0)