Skip to content

Commit d66506b

Browse files
committed
Data flow: Rename {Argument,Parameter}NodeExt to {Arg,Param}Node
1 parent c35a2b9 commit d66506b

29 files changed

+1372
-1786
lines changed

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

Lines changed: 48 additions & 64 deletions
Large diffs are not rendered by default.

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImpl2.qll

Lines changed: 48 additions & 64 deletions
Large diffs are not rendered by default.

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImpl3.qll

Lines changed: 48 additions & 64 deletions
Large diffs are not rendered by default.

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImpl4.qll

Lines changed: 48 additions & 64 deletions
Large diffs are not rendered by default.

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

Lines changed: 44 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,22 @@ predicate accessPathCostLimits(int apLimit, int tupleLimit) {
3535
* calls. For this reason, we cannot reuse the code from `DataFlowImpl.qll` directly.
3636
*/
3737
private module LambdaFlow {
38-
private predicate viableParamNonLambda(DataFlowCall call, int i, ParameterNodeExt p) {
38+
private predicate viableParamNonLambda(DataFlowCall call, int i, ParamNode p) {
3939
p.isParameterOf(viableCallable(call), i)
4040
}
4141

42-
private predicate viableParamLambda(DataFlowCall call, int i, ParameterNodeExt p) {
42+
private predicate viableParamLambda(DataFlowCall call, int i, ParamNode p) {
4343
p.isParameterOf(viableCallableLambda(call, _), i)
4444
}
4545

46-
private predicate viableParamArgNonLambda(
47-
DataFlowCall call, ParameterNodeExt p, ArgumentNodeExt arg
48-
) {
46+
private predicate viableParamArgNonLambda(DataFlowCall call, ParamNode p, ArgNode arg) {
4947
exists(int i |
5048
viableParamNonLambda(call, i, p) and
5149
arg.argumentOf(call, i)
5250
)
5351
}
5452

55-
private predicate viableParamArgLambda(DataFlowCall call, ParameterNodeExt p, ArgumentNodeExt arg) {
53+
private predicate viableParamArgLambda(DataFlowCall call, ParamNode p, ArgNode arg) {
5654
exists(int i |
5755
viableParamLambda(call, i, p) and
5856
arg.argumentOf(call, i)
@@ -120,7 +118,7 @@ private module LambdaFlow {
120118
boolean toJump, DataFlowCallOption lastCall
121119
) {
122120
revLambdaFlow0(lambdaCall, kind, node, t, toReturn, toJump, lastCall) and
123-
if castNode(node) or node instanceof ArgumentNodeExt or node instanceof ReturnNode
121+
if castNode(node) or node instanceof ArgNode or node instanceof ReturnNode
124122
then compatibleTypes(t, getNodeDataFlowType(node))
125123
else any()
126124
}
@@ -178,7 +176,7 @@ private module LambdaFlow {
178176
)
179177
or
180178
// flow into a callable
181-
exists(ParameterNodeExt p, DataFlowCallOption lastCall0, DataFlowCall call |
179+
exists(ParamNode p, DataFlowCallOption lastCall0, DataFlowCall call |
182180
revLambdaFlowIn(lambdaCall, kind, p, t, toJump, lastCall0) and
183181
(
184182
if lastCall0 = TDataFlowCallNone() and toJump = false
@@ -229,8 +227,8 @@ private module LambdaFlow {
229227

230228
pragma[nomagic]
231229
predicate revLambdaFlowIn(
232-
DataFlowCall lambdaCall, LambdaCallKind kind, ParameterNodeExt p, DataFlowType t,
233-
boolean toJump, DataFlowCallOption lastCall
230+
DataFlowCall lambdaCall, LambdaCallKind kind, ParamNode p, DataFlowType t, boolean toJump,
231+
DataFlowCallOption lastCall
234232
) {
235233
revLambdaFlow(lambdaCall, kind, p, t, false, toJump, lastCall)
236234
}
@@ -276,7 +274,7 @@ private module Cached {
276274
predicate outNodeExt(Node n) {
277275
n instanceof OutNode
278276
or
279-
n.(PostUpdateNode).getPreUpdateNode() instanceof ArgumentNodeExt
277+
n.(PostUpdateNode).getPreUpdateNode() instanceof ArgNode
280278
}
281279

282280
cached
@@ -286,7 +284,7 @@ private module Cached {
286284
OutNodeExt getAnOutNodeExt(DataFlowCall call, ReturnKindExt k) {
287285
result = getAnOutNode(call, k.(ValueReturnKind).getKind())
288286
or
289-
exists(ArgumentNodeExt arg |
287+
exists(ArgNode arg |
290288
result.(PostUpdateNode).getPreUpdateNode() = arg and
291289
arg.argumentOf(call, k.(ParamUpdateReturnKind).getPosition())
292290
)
@@ -296,7 +294,7 @@ private module Cached {
296294
predicate returnNodeExt(Node n, ReturnKindExt k) {
297295
k = TValueReturn(n.(ReturnNode).getKind())
298296
or
299-
exists(ParameterNodeExt p, int pos |
297+
exists(ParamNode p, int pos |
300298
parameterValueFlowsToPreUpdate(p, n) and
301299
p.isParameterOf(_, pos) and
302300
k = TParamUpdate(pos)
@@ -309,7 +307,7 @@ private module Cached {
309307
cached
310308
predicate castingNode(Node n) {
311309
castNode(n) or
312-
n instanceof ParameterNodeExt or
310+
n instanceof ParamNode or
313311
n instanceof OutNodeExt or
314312
// For reads, `x.f`, we want to check that the tracked type after the read (which
315313
// is obtained by popping the head of the access path stack) is compatible with
@@ -346,7 +344,7 @@ private module Cached {
346344
* The instance parameter is considered to have index `-1`.
347345
*/
348346
pragma[nomagic]
349-
private predicate viableParam(DataFlowCall call, int i, ParameterNodeExt p) {
347+
private predicate viableParam(DataFlowCall call, int i, ParamNode p) {
350348
p.isParameterOf(viableCallableExt(call), i)
351349
}
352350

@@ -355,7 +353,7 @@ private module Cached {
355353
* dispatch into account.
356354
*/
357355
cached
358-
predicate viableParamArg(DataFlowCall call, ParameterNodeExt p, ArgumentNodeExt arg) {
356+
predicate viableParamArg(DataFlowCall call, ParamNode p, ArgNode arg) {
359357
exists(int i |
360358
viableParam(call, i, p) and
361359
arg.argumentOf(call, i) and
@@ -397,7 +395,7 @@ private module Cached {
397395
* `read` indicates whether it is contents of `p` that can flow to `node`.
398396
*/
399397
pragma[nomagic]
400-
private predicate parameterValueFlowCand(ParameterNodeExt p, Node node, boolean read) {
398+
private predicate parameterValueFlowCand(ParamNode p, Node node, boolean read) {
401399
p = node and
402400
read = false
403401
or
@@ -415,27 +413,25 @@ private module Cached {
415413
)
416414
or
417415
// flow through: no prior read
418-
exists(ArgumentNodeExt arg |
416+
exists(ArgNode arg |
419417
parameterValueFlowArgCand(p, arg, false) and
420418
argumentValueFlowsThroughCand(arg, node, read)
421419
)
422420
or
423421
// flow through: no read inside method
424-
exists(ArgumentNodeExt arg |
422+
exists(ArgNode arg |
425423
parameterValueFlowArgCand(p, arg, read) and
426424
argumentValueFlowsThroughCand(arg, node, false)
427425
)
428426
}
429427

430428
pragma[nomagic]
431-
private predicate parameterValueFlowArgCand(
432-
ParameterNodeExt p, ArgumentNodeExt arg, boolean read
433-
) {
429+
private predicate parameterValueFlowArgCand(ParamNode p, ArgNode arg, boolean read) {
434430
parameterValueFlowCand(p, arg, read)
435431
}
436432

437433
pragma[nomagic]
438-
predicate parameterValueFlowsToPreUpdateCand(ParameterNodeExt p, PostUpdateNode n) {
434+
predicate parameterValueFlowsToPreUpdateCand(ParamNode p, PostUpdateNode n) {
439435
parameterValueFlowCand(p, n.getPreUpdateNode(), false)
440436
}
441437

@@ -447,7 +443,7 @@ private module Cached {
447443
* `read` indicates whether it is contents of `p` that can flow to the return
448444
* node.
449445
*/
450-
predicate parameterValueFlowReturnCand(ParameterNodeExt p, ReturnKind kind, boolean read) {
446+
predicate parameterValueFlowReturnCand(ParamNode p, ReturnKind kind, boolean read) {
451447
exists(ReturnNode ret |
452448
parameterValueFlowCand(p, ret, read) and
453449
kind = ret.getKind()
@@ -456,9 +452,9 @@ private module Cached {
456452

457453
pragma[nomagic]
458454
private predicate argumentValueFlowsThroughCand0(
459-
DataFlowCall call, ArgumentNodeExt arg, ReturnKind kind, boolean read
455+
DataFlowCall call, ArgNode arg, ReturnKind kind, boolean read
460456
) {
461-
exists(ParameterNodeExt param | viableParamArg(call, param, arg) |
457+
exists(ParamNode param | viableParamArg(call, param, arg) |
462458
parameterValueFlowReturnCand(param, kind, read)
463459
)
464460
}
@@ -469,14 +465,14 @@ private module Cached {
469465
*
470466
* `read` indicates whether it is contents of `arg` that can flow to `out`.
471467
*/
472-
predicate argumentValueFlowsThroughCand(ArgumentNodeExt arg, Node out, boolean read) {
468+
predicate argumentValueFlowsThroughCand(ArgNode arg, Node out, boolean read) {
473469
exists(DataFlowCall call, ReturnKind kind |
474470
argumentValueFlowsThroughCand0(call, arg, kind, read) and
475471
out = getAnOutNode(call, kind)
476472
)
477473
}
478474

479-
predicate cand(ParameterNodeExt p, Node n) {
475+
predicate cand(ParamNode p, Node n) {
480476
parameterValueFlowCand(p, n, _) and
481477
(
482478
parameterValueFlowReturnCand(p, _, _)
@@ -503,7 +499,7 @@ private module Cached {
503499
* If a read step was taken, then `read` captures the `Content`, the
504500
* container type, and the content type.
505501
*/
506-
predicate parameterValueFlow(ParameterNodeExt p, Node node, ReadStepTypesOption read) {
502+
predicate parameterValueFlow(ParamNode p, Node node, ReadStepTypesOption read) {
507503
parameterValueFlow0(p, node, read) and
508504
if node instanceof CastingNode
509505
then
@@ -517,7 +513,7 @@ private module Cached {
517513
}
518514

519515
pragma[nomagic]
520-
private predicate parameterValueFlow0(ParameterNodeExt p, Node node, ReadStepTypesOption read) {
516+
private predicate parameterValueFlow0(ParamNode p, Node node, ReadStepTypesOption read) {
521517
p = node and
522518
Cand::cand(p, _) and
523519
read = TReadStepTypesNone()
@@ -542,34 +538,32 @@ private module Cached {
542538

543539
pragma[nomagic]
544540
private predicate parameterValueFlow0_0(
545-
ReadStepTypesOption mustBeNone, ParameterNodeExt p, Node node, ReadStepTypesOption read
541+
ReadStepTypesOption mustBeNone, ParamNode p, Node node, ReadStepTypesOption read
546542
) {
547543
// flow through: no prior read
548-
exists(ArgumentNodeExt arg |
544+
exists(ArgNode arg |
549545
parameterValueFlowArg(p, arg, mustBeNone) and
550546
argumentValueFlowsThrough(arg, read, node)
551547
)
552548
or
553549
// flow through: no read inside method
554-
exists(ArgumentNodeExt arg |
550+
exists(ArgNode arg |
555551
parameterValueFlowArg(p, arg, read) and
556552
argumentValueFlowsThrough(arg, mustBeNone, node)
557553
)
558554
}
559555

560556
pragma[nomagic]
561-
private predicate parameterValueFlowArg(
562-
ParameterNodeExt p, ArgumentNodeExt arg, ReadStepTypesOption read
563-
) {
557+
private predicate parameterValueFlowArg(ParamNode p, ArgNode arg, ReadStepTypesOption read) {
564558
parameterValueFlow(p, arg, read) and
565559
Cand::argumentValueFlowsThroughCand(arg, _, _)
566560
}
567561

568562
pragma[nomagic]
569563
private predicate argumentValueFlowsThrough0(
570-
DataFlowCall call, ArgumentNodeExt arg, ReturnKind kind, ReadStepTypesOption read
564+
DataFlowCall call, ArgNode arg, ReturnKind kind, ReadStepTypesOption read
571565
) {
572-
exists(ParameterNodeExt param | viableParamArg(call, param, arg) |
566+
exists(ParamNode param | viableParamArg(call, param, arg) |
573567
parameterValueFlowReturn(param, kind, read)
574568
)
575569
}
@@ -583,7 +577,7 @@ private module Cached {
583577
* container type, and the content type.
584578
*/
585579
pragma[nomagic]
586-
predicate argumentValueFlowsThrough(ArgumentNodeExt arg, ReadStepTypesOption read, Node out) {
580+
predicate argumentValueFlowsThrough(ArgNode arg, ReadStepTypesOption read, Node out) {
587581
exists(DataFlowCall call, ReturnKind kind |
588582
argumentValueFlowsThrough0(call, arg, kind, read) and
589583
out = getAnOutNode(call, kind)
@@ -603,7 +597,7 @@ private module Cached {
603597
* value-preserving steps and a single read step, not taking call
604598
* contexts into account, thus representing a getter-step.
605599
*/
606-
predicate getterStep(ArgumentNodeExt arg, Content c, Node out) {
600+
predicate getterStep(ArgNode arg, Content c, Node out) {
607601
argumentValueFlowsThrough(arg, TReadStepTypesSome(_, c, _), out)
608602
}
609603

@@ -616,7 +610,7 @@ private module Cached {
616610
* container type, and the content type.
617611
*/
618612
private predicate parameterValueFlowReturn(
619-
ParameterNodeExt p, ReturnKind kind, ReadStepTypesOption read
613+
ParamNode p, ReturnKind kind, ReadStepTypesOption read
620614
) {
621615
exists(ReturnNode ret |
622616
parameterValueFlow(p, ret, read) and
@@ -722,7 +716,7 @@ private module Cached {
722716
* Holds if `p` can flow to the pre-update node associated with post-update
723717
* node `n`, in the same callable, using only value-preserving steps.
724718
*/
725-
private predicate parameterValueFlowsToPreUpdate(ParameterNodeExt p, PostUpdateNode n) {
719+
private predicate parameterValueFlowsToPreUpdate(ParamNode p, PostUpdateNode n) {
726720
parameterValueFlow(p, n.getPreUpdateNode(), TReadStepTypesNone())
727721
}
728722

@@ -778,8 +772,8 @@ private module Cached {
778772
// Does the language-specific simpleLocalFlowStep already model flow
779773
// from function input to output?
780774
fromPre = getAnOutNode(c, _) and
781-
toPre.(ArgumentNodeExt).argumentOf(c, _) and
782-
simpleLocalFlowStep(toPre.(ArgumentNodeExt), fromPre)
775+
toPre.(ArgNode).argumentOf(c, _) and
776+
simpleLocalFlowStep(toPre.(ArgNode), fromPre)
783777
)
784778
or
785779
argumentValueFlowsThrough(toPre, TReadStepTypesNone(), fromPre)
@@ -827,7 +821,7 @@ private module Cached {
827821
cached
828822
newtype TReturnKindExt =
829823
TValueReturn(ReturnKind kind) or
830-
TParamUpdate(int pos) { exists(ParameterNodeExt p | p.isParameterOf(_, pos)) }
824+
TParamUpdate(int pos) { exists(ParamNode p | p.isParameterOf(_, pos)) }
831825

832826
cached
833827
newtype TBooleanOption =
@@ -942,7 +936,7 @@ class CallContextSomeCall extends CallContextCall, TSomeCall {
942936
override string toString() { result = "CcSomeCall" }
943937

944938
override predicate relevantFor(DataFlowCallable callable) {
945-
exists(ParameterNodeExt p | getNodeEnclosingCallable(p) = callable)
939+
exists(ParamNode p | getNodeEnclosingCallable(p) = callable)
946940
}
947941

948942
override predicate matchesCall(DataFlowCall call) { any() }
@@ -1005,8 +999,8 @@ LocalCallContext getLocalCallContext(CallContext ctx, DataFlowCallable callable)
1005999
* The value of a parameter at function entry, viewed as a node in a data
10061000
* flow graph.
10071001
*/
1008-
class ParameterNodeExt extends Node {
1009-
ParameterNodeExt() { parameterNode(this, _, _) }
1002+
class ParamNode extends Node {
1003+
ParamNode() { parameterNode(this, _, _) }
10101004

10111005
/**
10121006
* Holds if this node is the parameter of callable `c` at the specified
@@ -1016,8 +1010,8 @@ class ParameterNodeExt extends Node {
10161010
}
10171011

10181012
/** A data-flow node that represents a call argument. */
1019-
class ArgumentNodeExt extends Node {
1020-
ArgumentNodeExt() { argumentNode(this, _, _) }
1013+
class ArgNode extends Node {
1014+
ArgNode() { argumentNode(this, _, _) }
10211015

10221016
/** Holds if this argument occurs at the given position in the given call. */
10231017
final predicate argumentOf(DataFlowCall call, int pos) { argumentNode(this, call, pos) }

0 commit comments

Comments
 (0)