Skip to content

Commit acc7d52

Browse files
committed
Data flow: Sync files
1 parent 6c0dbcf commit acc7d52

File tree

21 files changed

+708
-618
lines changed

21 files changed

+708
-618
lines changed

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

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -460,11 +460,11 @@ private predicate throughFlowNodeCand(Node node, Configuration config) {
460460
*/
461461
pragma[nomagic]
462462
private predicate simpleParameterFlow(
463-
ParameterNode p, Node node, DataFlowType t, Configuration config
463+
ParameterNode p, Node node, DataFlowErasedType t, Configuration config
464464
) {
465465
throughFlowNodeCand(node, config) and
466466
p = node and
467-
t = getErasedRepr(node.getType()) and
467+
t = getErasedNodeType(node) and
468468
exists(ReturnNode ret, ReturnKind kind |
469469
returnNodeGetEnclosingCallable(ret) = p.getEnclosingCallable() and
470470
kind = ret.getKind() and
@@ -475,29 +475,29 @@ private predicate simpleParameterFlow(
475475
exists(Node mid |
476476
simpleParameterFlow(p, mid, t, config) and
477477
localFlowStep(mid, node, config) and
478-
compatibleTypes(t, node.getType())
478+
compatibleTypes(t, getErasedNodeType(node))
479479
)
480480
or
481481
throughFlowNodeCand(node, unbind(config)) and
482482
exists(Node mid |
483483
simpleParameterFlow(p, mid, _, config) and
484484
additionalLocalFlowStep(mid, node, config) and
485-
t = getErasedRepr(node.getType())
485+
t = getErasedNodeType(node)
486486
)
487487
or
488488
throughFlowNodeCand(node, unbind(config)) and
489489
exists(Node mid |
490490
simpleParameterFlow(p, mid, t, config) and
491491
localStoreReadStep(mid, node) and
492-
compatibleTypes(t, node.getType())
492+
compatibleTypes(t, getErasedNodeType(node))
493493
)
494494
or
495495
// value flow through a callable
496496
throughFlowNodeCand(node, unbind(config)) and
497497
exists(Node arg |
498498
simpleParameterFlow(p, arg, t, config) and
499499
argumentValueFlowsThrough(arg, node, _) and
500-
compatibleTypes(t, node.getType())
500+
compatibleTypes(t, getErasedNodeType(node))
501501
)
502502
or
503503
// flow through a callable
@@ -510,7 +510,7 @@ private predicate simpleParameterFlow(
510510

511511
pragma[noinline]
512512
private predicate simpleArgumentFlowsThrough0(
513-
DataFlowCall call, ArgumentNode arg, ReturnKind kind, DataFlowType t, Configuration config
513+
DataFlowCall call, ArgumentNode arg, ReturnKind kind, DataFlowErasedType t, Configuration config
514514
) {
515515
nodeCand1(arg, unbind(config)) and
516516
not outBarrier(arg, config) and
@@ -529,7 +529,7 @@ private predicate simpleArgumentFlowsThrough0(
529529
* additional step from the configuration.
530530
*/
531531
private predicate simpleArgumentFlowsThrough(
532-
ArgumentNode arg, Node out, DataFlowType t, Configuration config
532+
ArgumentNode arg, Node out, DataFlowErasedType t, Configuration config
533533
) {
534534
exists(DataFlowCall call, ReturnKind kind |
535535
nodeCand1(out, unbind(config)) and
@@ -948,20 +948,20 @@ private predicate localFlowBigStep(
948948
}
949949

950950
private newtype TAccessPathFront =
951-
TFrontNil(DataFlowType t) or
951+
TFrontNil(DataFlowErasedType t) or
952952
TFrontHead(Content f)
953953

954954
/**
955955
* The front of an `AccessPath`. This is either a head or a nil.
956956
*/
957957
private class AccessPathFront extends TAccessPathFront {
958958
string toString() {
959-
exists(DataFlowType t | this = TFrontNil(t) | result = ppReprType(t))
959+
exists(DataFlowErasedType t | this = TFrontNil(t) | result = ppReprType(t))
960960
or
961961
exists(Content f | this = TFrontHead(f) | result = f.toString())
962962
}
963963

964-
DataFlowType getType() {
964+
DataFlowErasedType getType() {
965965
this = TFrontNil(result)
966966
or
967967
exists(Content head | this = TFrontHead(head) | result = head.getContainerType())
@@ -989,7 +989,9 @@ private class CastingNode extends Node {
989989
*/
990990
private predicate flowCandFwd(Node node, boolean fromArg, AccessPathFront apf, Configuration config) {
991991
flowCandFwd0(node, fromArg, apf, config) and
992-
if node instanceof CastingNode then compatibleTypes(node.getType(), apf.getType()) else any()
992+
if node instanceof CastingNode
993+
then compatibleTypes(getErasedNodeType(node), apf.getType())
994+
else any()
993995
}
994996

995997
/**
@@ -1010,7 +1012,7 @@ private class AccessPathFrontNilNode extends Node {
10101012
}
10111013

10121014
pragma[noinline]
1013-
private DataFlowType getErasedReprType() { result = getErasedRepr(this.getType()) }
1015+
private DataFlowErasedType getErasedReprType() { result = getErasedNodeType(this) }
10141016

10151017
/** Gets the `nil` path front for this node. */
10161018
AccessPathFrontNil getApf() { result = TFrontNil(this.getErasedReprType()) }
@@ -1067,7 +1069,7 @@ private predicate flowCandFwd0(Node node, boolean fromArg, AccessPathFront apf,
10671069
argumentValueFlowsThrough(mid, node, _)
10681070
)
10691071
or
1070-
exists(Node mid, AccessPathFrontNil nil, DataFlowType t |
1072+
exists(Node mid, AccessPathFrontNil nil, DataFlowErasedType t |
10711073
flowCandFwd(mid, fromArg, nil, config) and
10721074
simpleArgumentFlowsThrough(mid, node, t, config) and
10731075
apf = TFrontNil(t)
@@ -1220,8 +1222,8 @@ private predicate consCand(Content f, AccessPathFront apf, Configuration config)
12201222
}
12211223

12221224
private newtype TAccessPath =
1223-
TNil(DataFlowType t) or
1224-
TConsNil(Content f, DataFlowType t) { consCand(f, TFrontNil(t), _) } or
1225+
TNil(DataFlowErasedType t) or
1226+
TConsNil(Content f, DataFlowErasedType t) { consCand(f, TFrontNil(t), _) } or
12251227
TConsCons(Content f1, Content f2, int len) { consCand(f1, TFrontHead(f2), _) and len in [2 .. 5] }
12261228

12271229
/**
@@ -1248,7 +1250,7 @@ abstract private class AccessPath extends TAccessPath {
12481250
this = TConsCons(_, _, result)
12491251
}
12501252

1251-
DataFlowType getType() {
1253+
DataFlowErasedType getType() {
12521254
this = TNil(result)
12531255
or
12541256
result = this.getHead().getContainerType()
@@ -1264,11 +1266,11 @@ abstract private class AccessPath extends TAccessPath {
12641266

12651267
private class AccessPathNil extends AccessPath, TNil {
12661268
override string toString() {
1267-
exists(DataFlowType t | this = TNil(t) | result = concat(": " + ppReprType(t)))
1269+
exists(DataFlowErasedType t | this = TNil(t) | result = concat(": " + ppReprType(t)))
12681270
}
12691271

12701272
override AccessPathFront getFront() {
1271-
exists(DataFlowType t | this = TNil(t) | result = TFrontNil(t))
1273+
exists(DataFlowErasedType t | this = TNil(t) | result = TFrontNil(t))
12721274
}
12731275

12741276
override predicate pop(Content head, AccessPath tail) { none() }
@@ -1278,7 +1280,7 @@ abstract private class AccessPathCons extends AccessPath { }
12781280

12791281
private class AccessPathConsNil extends AccessPathCons, TConsNil {
12801282
override string toString() {
1281-
exists(Content f, DataFlowType t | this = TConsNil(f, t) |
1283+
exists(Content f, DataFlowErasedType t | this = TConsNil(f, t) |
12821284
// The `concat` becomes "" if `ppReprType` has no result.
12831285
result = "[" + f.toString() + "]" + concat(" : " + ppReprType(t))
12841286
)
@@ -1289,7 +1291,7 @@ private class AccessPathConsNil extends AccessPathCons, TConsNil {
12891291
}
12901292

12911293
override predicate pop(Content head, AccessPath tail) {
1292-
exists(DataFlowType t | this = TConsNil(head, t) and tail = TNil(t))
1294+
exists(DataFlowErasedType t | this = TConsNil(head, t) and tail = TNil(t))
12931295
}
12941296
}
12951297

@@ -1337,7 +1339,7 @@ private class AccessPathNilNode extends Node {
13371339
AccessPathNilNode() { flowCand(this.(AccessPathFrontNilNode), _, _, _) }
13381340

13391341
pragma[noinline]
1340-
private DataFlowType getErasedReprType() { result = getErasedRepr(this.getType()) }
1342+
private DataFlowErasedType getErasedReprType() { result = getErasedNodeType(this) }
13411343

13421344
/** Gets the `nil` path for this node. */
13431345
AccessPathNil getAp() { result = TNil(this.getErasedReprType()) }
@@ -1409,7 +1411,7 @@ private predicate flowFwd0(
14091411
argumentValueFlowsThrough(mid, node, _)
14101412
)
14111413
or
1412-
exists(Node mid, AccessPathNil nil, DataFlowType t |
1414+
exists(Node mid, AccessPathNil nil, DataFlowErasedType t |
14131415
flowFwd(mid, fromArg, _, nil, config) and
14141416
simpleArgumentFlowsThrough(mid, node, t, config) and
14151417
ap = TNil(t) and
@@ -2018,7 +2020,7 @@ private module FlowExploration {
20182020
}
20192021

20202022
private newtype TPartialAccessPath =
2021-
TPartialNil(DataFlowType t) or
2023+
TPartialNil(DataFlowErasedType t) or
20222024
TPartialCons(Content f, int len) { len in [1 .. 5] }
20232025

20242026
/**
@@ -2039,7 +2041,7 @@ private module FlowExploration {
20392041
this = TPartialCons(_, result)
20402042
}
20412043

2042-
DataFlowType getType() {
2044+
DataFlowErasedType getType() {
20432045
this = TPartialNil(result)
20442046
or
20452047
exists(Content head | this = TPartialCons(head, _) | result = head.getContainerType())
@@ -2050,11 +2052,11 @@ private module FlowExploration {
20502052

20512053
private class PartialAccessPathNil extends PartialAccessPath, TPartialNil {
20522054
override string toString() {
2053-
exists(DataFlowType t | this = TPartialNil(t) | result = concat(": " + ppReprType(t)))
2055+
exists(DataFlowErasedType t | this = TPartialNil(t) | result = concat(": " + ppReprType(t)))
20542056
}
20552057

20562058
override AccessPathFront getFront() {
2057-
exists(DataFlowType t | this = TPartialNil(t) | result = TFrontNil(t))
2059+
exists(DataFlowErasedType t | this = TPartialNil(t) | result = TFrontNil(t))
20582060
}
20592061
}
20602062

@@ -2076,7 +2078,7 @@ private module FlowExploration {
20762078
TPartialPathNodeMk(Node node, CallContext cc, PartialAccessPath ap, Configuration config) {
20772079
config.isSource(node) and
20782080
cc instanceof CallContextAny and
2079-
ap = TPartialNil(getErasedRepr(node.getType())) and
2081+
ap = TPartialNil(getErasedNodeType(node)) and
20802082
not fullBarrier(node, config) and
20812083
exists(config.explorationLimit())
20822084
or
@@ -2091,7 +2093,9 @@ private module FlowExploration {
20912093
exists(PartialPathNode mid |
20922094
partialPathStep(mid, node, cc, ap, config) and
20932095
not fullBarrier(node, config) and
2094-
if node instanceof CastingNode then compatibleTypes(node.getType(), ap.getType()) else any()
2096+
if node instanceof CastingNode
2097+
then compatibleTypes(getErasedNodeType(node), ap.getType())
2098+
else any()
20952099
)
20962100
}
20972101

@@ -2194,7 +2198,7 @@ private module FlowExploration {
21942198
additionalLocalFlowStep(mid.getNode(), node, config) and
21952199
cc = mid.getCallContext() and
21962200
mid.getAp() instanceof PartialAccessPathNil and
2197-
ap = TPartialNil(getErasedRepr(node.getType())) and
2201+
ap = TPartialNil(getErasedNodeType(node)) and
21982202
config = mid.getConfiguration()
21992203
)
22002204
or
@@ -2206,7 +2210,7 @@ private module FlowExploration {
22062210
additionalJumpStep(mid.getNode(), node, config) and
22072211
cc instanceof CallContextAny and
22082212
mid.getAp() instanceof PartialAccessPathNil and
2209-
ap = TPartialNil(getErasedRepr(node.getType())) and
2213+
ap = TPartialNil(getErasedNodeType(node)) and
22102214
config = mid.getConfiguration()
22112215
or
22122216
partialPathStoreStep(mid, _, _, node, ap) and

0 commit comments

Comments
 (0)