Skip to content

Commit 38b73ff

Browse files
authored
Merge pull request github#3854 from hvitved/dataflow/node-type-interface
Data flow: Replace `getErasedRepr()` and `Node::getTypeBound()` with `getNodeType()`
2 parents ef109d9 + f1179cc commit 38b73ff

39 files changed

+396
-495
lines changed

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

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,11 +1124,11 @@ private module LocalFlowBigStep {
11241124
(
11251125
localFlowStepNodeCand1(node1, node2, config) and
11261126
preservesValue = true and
1127-
t = getErasedNodeTypeBound(node1)
1127+
t = getNodeType(node1)
11281128
or
11291129
additionalLocalFlowStepNodeCand2(node1, node2, config) and
11301130
preservesValue = false and
1131-
t = getErasedNodeTypeBound(node2)
1131+
t = getNodeType(node2)
11321132
) and
11331133
node1 != node2 and
11341134
cc.relevantFor(node1.getEnclosingCallable()) and
@@ -1147,7 +1147,7 @@ private module LocalFlowBigStep {
11471147
additionalLocalFlowStepNodeCand2(mid, node2, config) and
11481148
not mid instanceof FlowCheckNode and
11491149
preservesValue = false and
1150-
t = getErasedNodeTypeBound(node2) and
1150+
t = getNodeType(node2) and
11511151
nodeCand2(node2, unbind(config))
11521152
)
11531153
)
@@ -1202,9 +1202,7 @@ private predicate flowCandFwd(
12021202
) {
12031203
flowCandFwd0(node, fromArg, argApf, apf, config) and
12041204
not apf.isClearedAt(node) and
1205-
if node instanceof CastingNode
1206-
then compatibleTypes(getErasedNodeTypeBound(node), apf.getType())
1207-
else any()
1205+
if node instanceof CastingNode then compatibleTypes(getNodeType(node), apf.getType()) else any()
12081206
}
12091207

12101208
pragma[nomagic]
@@ -1216,7 +1214,7 @@ private predicate flowCandFwd0(
12161214
config.isSource(node) and
12171215
fromArg = false and
12181216
argApf = TAccessPathFrontNone() and
1219-
apf = TFrontNil(getErasedNodeTypeBound(node))
1217+
apf = TFrontNil(getNodeType(node))
12201218
or
12211219
exists(Node mid |
12221220
flowCandFwd(mid, fromArg, argApf, apf, config) and
@@ -1242,7 +1240,7 @@ private predicate flowCandFwd0(
12421240
additionalJumpStep(mid, node, config) and
12431241
fromArg = false and
12441242
argApf = TAccessPathFrontNone() and
1245-
apf = TFrontNil(getErasedNodeTypeBound(node))
1243+
apf = TFrontNil(getNodeType(node))
12461244
)
12471245
or
12481246
// store
@@ -1672,7 +1670,7 @@ private predicate flowFwd0(
16721670
config.isSource(node) and
16731671
fromArg = false and
16741672
argAp = TAccessPathNone() and
1675-
ap = TNil(getErasedNodeTypeBound(node)) and
1673+
ap = TNil(getNodeType(node)) and
16761674
apf = ap.(AccessPathNil).getFront()
16771675
or
16781676
flowCand(node, _, _, _, unbind(config)) and
@@ -1700,7 +1698,7 @@ private predicate flowFwd0(
17001698
additionalJumpStep(mid, node, config) and
17011699
fromArg = false and
17021700
argAp = TAccessPathNone() and
1703-
ap = TNil(getErasedNodeTypeBound(node)) and
1701+
ap = TNil(getNodeType(node)) and
17041702
apf = ap.(AccessPathNil).getFront()
17051703
)
17061704
)
@@ -2077,7 +2075,7 @@ private newtype TPathNode =
20772075
config.isSource(node) and
20782076
cc instanceof CallContextAny and
20792077
sc instanceof SummaryCtxNone and
2080-
ap = TNil(getErasedNodeTypeBound(node))
2078+
ap = TNil(getNodeType(node))
20812079
or
20822080
// ... or a step from an existing PathNode to another node.
20832081
exists(PathNodeMid mid |
@@ -2304,7 +2302,7 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
23042302
cc instanceof CallContextAny and
23052303
sc instanceof SummaryCtxNone and
23062304
mid.getAp() instanceof AccessPathNil and
2307-
ap = TNil(getErasedNodeTypeBound(node))
2305+
ap = TNil(getNodeType(node))
23082306
or
23092307
exists(TypedContent tc | pathStoreStep(mid, node, pop(tc, ap), tc, cc)) and
23102308
sc = mid.getSummaryCtx()
@@ -2646,7 +2644,7 @@ private module FlowExploration {
26462644
cc instanceof CallContextAny and
26472645
sc1 = TSummaryCtx1None() and
26482646
sc2 = TSummaryCtx2None() and
2649-
ap = TPartialNil(getErasedNodeTypeBound(node)) and
2647+
ap = TPartialNil(getNodeType(node)) and
26502648
not fullBarrier(node, config) and
26512649
exists(config.explorationLimit())
26522650
or
@@ -2663,7 +2661,7 @@ private module FlowExploration {
26632661
partialPathStep(mid, node, cc, sc1, sc2, ap, config) and
26642662
not fullBarrier(node, config) and
26652663
if node instanceof CastingNode
2666-
then compatibleTypes(getErasedNodeTypeBound(node), ap.getType())
2664+
then compatibleTypes(getNodeType(node), ap.getType())
26672665
else any()
26682666
)
26692667
}
@@ -2776,7 +2774,7 @@ private module FlowExploration {
27762774
sc1 = mid.getSummaryCtx1() and
27772775
sc2 = mid.getSummaryCtx2() and
27782776
mid.getAp() instanceof PartialAccessPathNil and
2779-
ap = TPartialNil(getErasedNodeTypeBound(node)) and
2777+
ap = TPartialNil(getNodeType(node)) and
27802778
config = mid.getConfiguration()
27812779
)
27822780
or
@@ -2792,7 +2790,7 @@ private module FlowExploration {
27922790
sc1 = TSummaryCtx1None() and
27932791
sc2 = TSummaryCtx2None() and
27942792
mid.getAp() instanceof PartialAccessPathNil and
2795-
ap = TPartialNil(getErasedNodeTypeBound(node)) and
2793+
ap = TPartialNil(getNodeType(node)) and
27962794
config = mid.getConfiguration()
27972795
or
27982796
partialPathStoreStep(mid, _, _, node, ap) and
@@ -2806,7 +2804,7 @@ private module FlowExploration {
28062804
sc1 = mid.getSummaryCtx1() and
28072805
sc2 = mid.getSummaryCtx2() and
28082806
apConsFwd(ap, tc, ap0, config) and
2809-
compatibleTypes(ap.getType(), getErasedNodeTypeBound(node))
2807+
compatibleTypes(ap.getType(), getNodeType(node))
28102808
)
28112809
or
28122810
partialPathIntoCallable(mid, node, _, cc, sc1, sc2, _, ap, config)

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

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,11 +1124,11 @@ private module LocalFlowBigStep {
11241124
(
11251125
localFlowStepNodeCand1(node1, node2, config) and
11261126
preservesValue = true and
1127-
t = getErasedNodeTypeBound(node1)
1127+
t = getNodeType(node1)
11281128
or
11291129
additionalLocalFlowStepNodeCand2(node1, node2, config) and
11301130
preservesValue = false and
1131-
t = getErasedNodeTypeBound(node2)
1131+
t = getNodeType(node2)
11321132
) and
11331133
node1 != node2 and
11341134
cc.relevantFor(node1.getEnclosingCallable()) and
@@ -1147,7 +1147,7 @@ private module LocalFlowBigStep {
11471147
additionalLocalFlowStepNodeCand2(mid, node2, config) and
11481148
not mid instanceof FlowCheckNode and
11491149
preservesValue = false and
1150-
t = getErasedNodeTypeBound(node2) and
1150+
t = getNodeType(node2) and
11511151
nodeCand2(node2, unbind(config))
11521152
)
11531153
)
@@ -1202,9 +1202,7 @@ private predicate flowCandFwd(
12021202
) {
12031203
flowCandFwd0(node, fromArg, argApf, apf, config) and
12041204
not apf.isClearedAt(node) and
1205-
if node instanceof CastingNode
1206-
then compatibleTypes(getErasedNodeTypeBound(node), apf.getType())
1207-
else any()
1205+
if node instanceof CastingNode then compatibleTypes(getNodeType(node), apf.getType()) else any()
12081206
}
12091207

12101208
pragma[nomagic]
@@ -1216,7 +1214,7 @@ private predicate flowCandFwd0(
12161214
config.isSource(node) and
12171215
fromArg = false and
12181216
argApf = TAccessPathFrontNone() and
1219-
apf = TFrontNil(getErasedNodeTypeBound(node))
1217+
apf = TFrontNil(getNodeType(node))
12201218
or
12211219
exists(Node mid |
12221220
flowCandFwd(mid, fromArg, argApf, apf, config) and
@@ -1242,7 +1240,7 @@ private predicate flowCandFwd0(
12421240
additionalJumpStep(mid, node, config) and
12431241
fromArg = false and
12441242
argApf = TAccessPathFrontNone() and
1245-
apf = TFrontNil(getErasedNodeTypeBound(node))
1243+
apf = TFrontNil(getNodeType(node))
12461244
)
12471245
or
12481246
// store
@@ -1672,7 +1670,7 @@ private predicate flowFwd0(
16721670
config.isSource(node) and
16731671
fromArg = false and
16741672
argAp = TAccessPathNone() and
1675-
ap = TNil(getErasedNodeTypeBound(node)) and
1673+
ap = TNil(getNodeType(node)) and
16761674
apf = ap.(AccessPathNil).getFront()
16771675
or
16781676
flowCand(node, _, _, _, unbind(config)) and
@@ -1700,7 +1698,7 @@ private predicate flowFwd0(
17001698
additionalJumpStep(mid, node, config) and
17011699
fromArg = false and
17021700
argAp = TAccessPathNone() and
1703-
ap = TNil(getErasedNodeTypeBound(node)) and
1701+
ap = TNil(getNodeType(node)) and
17041702
apf = ap.(AccessPathNil).getFront()
17051703
)
17061704
)
@@ -2077,7 +2075,7 @@ private newtype TPathNode =
20772075
config.isSource(node) and
20782076
cc instanceof CallContextAny and
20792077
sc instanceof SummaryCtxNone and
2080-
ap = TNil(getErasedNodeTypeBound(node))
2078+
ap = TNil(getNodeType(node))
20812079
or
20822080
// ... or a step from an existing PathNode to another node.
20832081
exists(PathNodeMid mid |
@@ -2304,7 +2302,7 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
23042302
cc instanceof CallContextAny and
23052303
sc instanceof SummaryCtxNone and
23062304
mid.getAp() instanceof AccessPathNil and
2307-
ap = TNil(getErasedNodeTypeBound(node))
2305+
ap = TNil(getNodeType(node))
23082306
or
23092307
exists(TypedContent tc | pathStoreStep(mid, node, pop(tc, ap), tc, cc)) and
23102308
sc = mid.getSummaryCtx()
@@ -2646,7 +2644,7 @@ private module FlowExploration {
26462644
cc instanceof CallContextAny and
26472645
sc1 = TSummaryCtx1None() and
26482646
sc2 = TSummaryCtx2None() and
2649-
ap = TPartialNil(getErasedNodeTypeBound(node)) and
2647+
ap = TPartialNil(getNodeType(node)) and
26502648
not fullBarrier(node, config) and
26512649
exists(config.explorationLimit())
26522650
or
@@ -2663,7 +2661,7 @@ private module FlowExploration {
26632661
partialPathStep(mid, node, cc, sc1, sc2, ap, config) and
26642662
not fullBarrier(node, config) and
26652663
if node instanceof CastingNode
2666-
then compatibleTypes(getErasedNodeTypeBound(node), ap.getType())
2664+
then compatibleTypes(getNodeType(node), ap.getType())
26672665
else any()
26682666
)
26692667
}
@@ -2776,7 +2774,7 @@ private module FlowExploration {
27762774
sc1 = mid.getSummaryCtx1() and
27772775
sc2 = mid.getSummaryCtx2() and
27782776
mid.getAp() instanceof PartialAccessPathNil and
2779-
ap = TPartialNil(getErasedNodeTypeBound(node)) and
2777+
ap = TPartialNil(getNodeType(node)) and
27802778
config = mid.getConfiguration()
27812779
)
27822780
or
@@ -2792,7 +2790,7 @@ private module FlowExploration {
27922790
sc1 = TSummaryCtx1None() and
27932791
sc2 = TSummaryCtx2None() and
27942792
mid.getAp() instanceof PartialAccessPathNil and
2795-
ap = TPartialNil(getErasedNodeTypeBound(node)) and
2793+
ap = TPartialNil(getNodeType(node)) and
27962794
config = mid.getConfiguration()
27972795
or
27982796
partialPathStoreStep(mid, _, _, node, ap) and
@@ -2806,7 +2804,7 @@ private module FlowExploration {
28062804
sc1 = mid.getSummaryCtx1() and
28072805
sc2 = mid.getSummaryCtx2() and
28082806
apConsFwd(ap, tc, ap0, config) and
2809-
compatibleTypes(ap.getType(), getErasedNodeTypeBound(node))
2807+
compatibleTypes(ap.getType(), getNodeType(node))
28102808
)
28112809
or
28122810
partialPathIntoCallable(mid, node, _, cc, sc1, sc2, _, ap, config)

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

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,11 +1124,11 @@ private module LocalFlowBigStep {
11241124
(
11251125
localFlowStepNodeCand1(node1, node2, config) and
11261126
preservesValue = true and
1127-
t = getErasedNodeTypeBound(node1)
1127+
t = getNodeType(node1)
11281128
or
11291129
additionalLocalFlowStepNodeCand2(node1, node2, config) and
11301130
preservesValue = false and
1131-
t = getErasedNodeTypeBound(node2)
1131+
t = getNodeType(node2)
11321132
) and
11331133
node1 != node2 and
11341134
cc.relevantFor(node1.getEnclosingCallable()) and
@@ -1147,7 +1147,7 @@ private module LocalFlowBigStep {
11471147
additionalLocalFlowStepNodeCand2(mid, node2, config) and
11481148
not mid instanceof FlowCheckNode and
11491149
preservesValue = false and
1150-
t = getErasedNodeTypeBound(node2) and
1150+
t = getNodeType(node2) and
11511151
nodeCand2(node2, unbind(config))
11521152
)
11531153
)
@@ -1202,9 +1202,7 @@ private predicate flowCandFwd(
12021202
) {
12031203
flowCandFwd0(node, fromArg, argApf, apf, config) and
12041204
not apf.isClearedAt(node) and
1205-
if node instanceof CastingNode
1206-
then compatibleTypes(getErasedNodeTypeBound(node), apf.getType())
1207-
else any()
1205+
if node instanceof CastingNode then compatibleTypes(getNodeType(node), apf.getType()) else any()
12081206
}
12091207

12101208
pragma[nomagic]
@@ -1216,7 +1214,7 @@ private predicate flowCandFwd0(
12161214
config.isSource(node) and
12171215
fromArg = false and
12181216
argApf = TAccessPathFrontNone() and
1219-
apf = TFrontNil(getErasedNodeTypeBound(node))
1217+
apf = TFrontNil(getNodeType(node))
12201218
or
12211219
exists(Node mid |
12221220
flowCandFwd(mid, fromArg, argApf, apf, config) and
@@ -1242,7 +1240,7 @@ private predicate flowCandFwd0(
12421240
additionalJumpStep(mid, node, config) and
12431241
fromArg = false and
12441242
argApf = TAccessPathFrontNone() and
1245-
apf = TFrontNil(getErasedNodeTypeBound(node))
1243+
apf = TFrontNil(getNodeType(node))
12461244
)
12471245
or
12481246
// store
@@ -1672,7 +1670,7 @@ private predicate flowFwd0(
16721670
config.isSource(node) and
16731671
fromArg = false and
16741672
argAp = TAccessPathNone() and
1675-
ap = TNil(getErasedNodeTypeBound(node)) and
1673+
ap = TNil(getNodeType(node)) and
16761674
apf = ap.(AccessPathNil).getFront()
16771675
or
16781676
flowCand(node, _, _, _, unbind(config)) and
@@ -1700,7 +1698,7 @@ private predicate flowFwd0(
17001698
additionalJumpStep(mid, node, config) and
17011699
fromArg = false and
17021700
argAp = TAccessPathNone() and
1703-
ap = TNil(getErasedNodeTypeBound(node)) and
1701+
ap = TNil(getNodeType(node)) and
17041702
apf = ap.(AccessPathNil).getFront()
17051703
)
17061704
)
@@ -2077,7 +2075,7 @@ private newtype TPathNode =
20772075
config.isSource(node) and
20782076
cc instanceof CallContextAny and
20792077
sc instanceof SummaryCtxNone and
2080-
ap = TNil(getErasedNodeTypeBound(node))
2078+
ap = TNil(getNodeType(node))
20812079
or
20822080
// ... or a step from an existing PathNode to another node.
20832081
exists(PathNodeMid mid |
@@ -2304,7 +2302,7 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
23042302
cc instanceof CallContextAny and
23052303
sc instanceof SummaryCtxNone and
23062304
mid.getAp() instanceof AccessPathNil and
2307-
ap = TNil(getErasedNodeTypeBound(node))
2305+
ap = TNil(getNodeType(node))
23082306
or
23092307
exists(TypedContent tc | pathStoreStep(mid, node, pop(tc, ap), tc, cc)) and
23102308
sc = mid.getSummaryCtx()
@@ -2646,7 +2644,7 @@ private module FlowExploration {
26462644
cc instanceof CallContextAny and
26472645
sc1 = TSummaryCtx1None() and
26482646
sc2 = TSummaryCtx2None() and
2649-
ap = TPartialNil(getErasedNodeTypeBound(node)) and
2647+
ap = TPartialNil(getNodeType(node)) and
26502648
not fullBarrier(node, config) and
26512649
exists(config.explorationLimit())
26522650
or
@@ -2663,7 +2661,7 @@ private module FlowExploration {
26632661
partialPathStep(mid, node, cc, sc1, sc2, ap, config) and
26642662
not fullBarrier(node, config) and
26652663
if node instanceof CastingNode
2666-
then compatibleTypes(getErasedNodeTypeBound(node), ap.getType())
2664+
then compatibleTypes(getNodeType(node), ap.getType())
26672665
else any()
26682666
)
26692667
}
@@ -2776,7 +2774,7 @@ private module FlowExploration {
27762774
sc1 = mid.getSummaryCtx1() and
27772775
sc2 = mid.getSummaryCtx2() and
27782776
mid.getAp() instanceof PartialAccessPathNil and
2779-
ap = TPartialNil(getErasedNodeTypeBound(node)) and
2777+
ap = TPartialNil(getNodeType(node)) and
27802778
config = mid.getConfiguration()
27812779
)
27822780
or
@@ -2792,7 +2790,7 @@ private module FlowExploration {
27922790
sc1 = TSummaryCtx1None() and
27932791
sc2 = TSummaryCtx2None() and
27942792
mid.getAp() instanceof PartialAccessPathNil and
2795-
ap = TPartialNil(getErasedNodeTypeBound(node)) and
2793+
ap = TPartialNil(getNodeType(node)) and
27962794
config = mid.getConfiguration()
27972795
or
27982796
partialPathStoreStep(mid, _, _, node, ap) and
@@ -2806,7 +2804,7 @@ private module FlowExploration {
28062804
sc1 = mid.getSummaryCtx1() and
28072805
sc2 = mid.getSummaryCtx2() and
28082806
apConsFwd(ap, tc, ap0, config) and
2809-
compatibleTypes(ap.getType(), getErasedNodeTypeBound(node))
2807+
compatibleTypes(ap.getType(), getNodeType(node))
28102808
)
28112809
or
28122810
partialPathIntoCallable(mid, node, _, cc, sc1, sc2, _, ap, config)

0 commit comments

Comments
 (0)