Skip to content

Commit d58a6b0

Browse files
authored
Merge pull request #2396 from hvitved/dataflow/erased-type-class
Approved by aschackmull, jbj
2 parents 0f91139 + a26efdf commit d58a6b0

24 files changed

+409
-309
lines changed

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ private predicate simpleParameterFlow(
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
@@ -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 DataFlowType getErasedReprType() { result = getErasedNodeType(this) }
10141016

10151017
/** Gets the `nil` path front for this node. */
10161018
AccessPathFrontNil getApf() { result = TFrontNil(this.getErasedReprType()) }
@@ -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 DataFlowType getErasedReprType() { result = getErasedNodeType(this) }
13411343

13421344
/** Gets the `nil` path for this node. */
13431345
AccessPathNil getAp() { result = TNil(this.getErasedReprType()) }
@@ -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

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ private predicate simpleParameterFlow(
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
@@ -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 DataFlowType getErasedReprType() { result = getErasedNodeType(this) }
10141016

10151017
/** Gets the `nil` path front for this node. */
10161018
AccessPathFrontNil getApf() { result = TFrontNil(this.getErasedReprType()) }
@@ -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 DataFlowType getErasedReprType() { result = getErasedNodeType(this) }
13411343

13421344
/** Gets the `nil` path for this node. */
13431345
AccessPathNil getAp() { result = TNil(this.getErasedReprType()) }
@@ -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

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ private predicate simpleParameterFlow(
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
@@ -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 DataFlowType getErasedReprType() { result = getErasedNodeType(this) }
10141016

10151017
/** Gets the `nil` path front for this node. */
10161018
AccessPathFrontNil getApf() { result = TFrontNil(this.getErasedReprType()) }
@@ -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 DataFlowType getErasedReprType() { result = getErasedNodeType(this) }
13411343

13421344
/** Gets the `nil` path for this node. */
13431345
AccessPathNil getAp() { result = TNil(this.getErasedReprType()) }
@@ -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)