Skip to content

Commit ade99c2

Browse files
committed
Data flow: Cache Cast(ing)Node
1 parent 346af4f commit ade99c2

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,7 @@ private module LocalFlowBigStep {
12571257
*/
12581258
private class FlowCheckNode extends Node {
12591259
FlowCheckNode() {
1260-
this instanceof CastNode or
1260+
castNode(this) or
12611261
clearsContentCached(this, _)
12621262
}
12631263
}

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ private module LambdaFlow {
118118
boolean toJump, DataFlowCallOption lastCall
119119
) {
120120
revLambdaFlow0(lambdaCall, kind, node, t, toReturn, toJump, lastCall) and
121-
if node instanceof CastNode or node instanceof ArgumentNode or node instanceof ReturnNode
121+
if castNode(node) or node instanceof ArgumentNode or node instanceof ReturnNode
122122
then compatibleTypes(t, getNodeDataFlowType(node))
123123
else any()
124124
}
@@ -290,6 +290,20 @@ private module Cached {
290290
)
291291
}
292292

293+
cached
294+
predicate castNode(Node n) { n instanceof CastNode }
295+
296+
cached
297+
predicate castingNode(Node n) {
298+
castNode(n) or
299+
n instanceof ParameterNode or
300+
n instanceof OutNodeExt or
301+
// For reads, `x.f`, we want to check that the tracked type after the read (which
302+
// is obtained by popping the head of the access path stack) is compatible with
303+
// the type of `x.f`.
304+
read(_, _, n)
305+
}
306+
293307
/**
294308
* Gets a viable target for the lambda call `call`.
295309
*
@@ -818,15 +832,7 @@ private module Cached {
818832
* A `Node` at which a cast can occur such that the type should be checked.
819833
*/
820834
class CastingNode extends Node {
821-
CastingNode() {
822-
this instanceof ParameterNode or
823-
this instanceof CastNode or
824-
this instanceof OutNodeExt or
825-
// For reads, `x.f`, we want to check that the tracked type after the read (which
826-
// is obtained by popping the head of the access path stack) is compatible with
827-
// the type of `x.f`.
828-
read(_, _, this)
829-
}
835+
CastingNode() { castingNode(this) }
830836
}
831837

832838
private predicate readStepWithTypes(

0 commit comments

Comments
 (0)