Skip to content

Commit d230509

Browse files
committed
Dataflow: Address review comments.
1 parent 95afd55 commit d230509

File tree

8 files changed

+120
-240
lines changed

8 files changed

+120
-240
lines changed

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

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,7 @@ module Impl<FullStateConfigSig Config> {
12111211
filter(node, state, t0, ap, t)
12121212
}
12131213

1214+
pragma[nomagic]
12141215
private predicate typeStrengthen(Typ t0, Ap ap, Typ t) {
12151216
fwdFlow1(_, _, _, _, _, _, t0, t, ap, _) and t0 != t
12161217
}
@@ -2255,6 +2256,16 @@ module Impl<FullStateConfigSig Config> {
22552256
import MkStage<Stage2>::Stage<Stage3Param>
22562257
}
22572258

2259+
bindingset[node, t0]
2260+
private predicate strengthenType(NodeEx node, DataFlowType t0, DataFlowType t) {
2261+
if castingNodeEx(node)
2262+
then
2263+
exists(DataFlowType nt | nt = node.getDataFlowType() |
2264+
if typeStrongerThan(nt, t0) then t = nt else (compatibleTypes(nt, t0) and t = t0)
2265+
)
2266+
else t = t0
2267+
}
2268+
22582269
private module Stage4Param implements MkStage<Stage3>::StageParam {
22592270
private module PrevStage = Stage3;
22602271

@@ -2351,14 +2362,7 @@ module Impl<FullStateConfigSig Config> {
23512362
predicate filter(NodeEx node, FlowState state, Typ t0, Ap ap, Typ t) {
23522363
exists(state) and
23532364
not clear(node, ap) and
2354-
(
2355-
if castingNodeEx(node)
2356-
then
2357-
exists(Typ nt | nt = node.getDataFlowType() |
2358-
if typeStrongerThan(nt, t0) then t = nt else (compatibleTypes(nt, t0) and t = t0)
2359-
)
2360-
else t = t0
2361-
) and
2365+
strengthenType(node, t0, t) and
23622366
(
23632367
notExpectsContent(node)
23642368
or
@@ -2632,14 +2636,7 @@ module Impl<FullStateConfigSig Config> {
26322636

26332637
bindingset[node, state, t0, ap]
26342638
predicate filter(NodeEx node, FlowState state, Typ t0, Ap ap, Typ t) {
2635-
(
2636-
if castingNodeEx(node)
2637-
then
2638-
exists(Typ nt | nt = node.getDataFlowType() |
2639-
if typeStrongerThan(nt, t0) then t = nt else (compatibleTypes(nt, t0) and t = t0)
2640-
)
2641-
else t = t0
2642-
) and
2639+
strengthenType(node, t0, t) and
26432640
exists(state) and
26442641
exists(ap)
26452642
}
@@ -3373,14 +3370,7 @@ module Impl<FullStateConfigSig Config> {
33733370
exists(DataFlowType t0 |
33743371
pathStep0(mid, node, state, cc, sc, t0, ap) and
33753372
Stage5::revFlow(node, state, ap.getApprox()) and
3376-
(
3377-
if castingNodeEx(node)
3378-
then
3379-
exists(DataFlowType nt | nt = node.getDataFlowType() |
3380-
if typeStrongerThan(nt, t0) then t = nt else (compatibleTypes(nt, t0) and t = t0)
3381-
)
3382-
else t = t0
3383-
)
3373+
strengthenType(node, t0, t)
33843374
)
33853375
}
33863376

@@ -4055,12 +4045,7 @@ module Impl<FullStateConfigSig Config> {
40554045
notExpectsContent(node) or
40564046
expectsContentEx(node, ap.getHead())
40574047
) and
4058-
if castingNodeEx(node)
4059-
then
4060-
exists(DataFlowType nt | nt = node.getDataFlowType() |
4061-
if typeStrongerThan(nt, t0) then t = nt else (compatibleTypes(nt, t0) and t = t0)
4062-
)
4063-
else t = t0
4048+
strengthenType(node, t0, t)
40644049
}
40654050

40664051
pragma[nomagic]

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowImpl.qll

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,7 @@ module Impl<FullStateConfigSig Config> {
12111211
filter(node, state, t0, ap, t)
12121212
}
12131213

1214+
pragma[nomagic]
12141215
private predicate typeStrengthen(Typ t0, Ap ap, Typ t) {
12151216
fwdFlow1(_, _, _, _, _, _, t0, t, ap, _) and t0 != t
12161217
}
@@ -2255,6 +2256,16 @@ module Impl<FullStateConfigSig Config> {
22552256
import MkStage<Stage2>::Stage<Stage3Param>
22562257
}
22572258

2259+
bindingset[node, t0]
2260+
private predicate strengthenType(NodeEx node, DataFlowType t0, DataFlowType t) {
2261+
if castingNodeEx(node)
2262+
then
2263+
exists(DataFlowType nt | nt = node.getDataFlowType() |
2264+
if typeStrongerThan(nt, t0) then t = nt else (compatibleTypes(nt, t0) and t = t0)
2265+
)
2266+
else t = t0
2267+
}
2268+
22582269
private module Stage4Param implements MkStage<Stage3>::StageParam {
22592270
private module PrevStage = Stage3;
22602271

@@ -2351,14 +2362,7 @@ module Impl<FullStateConfigSig Config> {
23512362
predicate filter(NodeEx node, FlowState state, Typ t0, Ap ap, Typ t) {
23522363
exists(state) and
23532364
not clear(node, ap) and
2354-
(
2355-
if castingNodeEx(node)
2356-
then
2357-
exists(Typ nt | nt = node.getDataFlowType() |
2358-
if typeStrongerThan(nt, t0) then t = nt else (compatibleTypes(nt, t0) and t = t0)
2359-
)
2360-
else t = t0
2361-
) and
2365+
strengthenType(node, t0, t) and
23622366
(
23632367
notExpectsContent(node)
23642368
or
@@ -2632,14 +2636,7 @@ module Impl<FullStateConfigSig Config> {
26322636

26332637
bindingset[node, state, t0, ap]
26342638
predicate filter(NodeEx node, FlowState state, Typ t0, Ap ap, Typ t) {
2635-
(
2636-
if castingNodeEx(node)
2637-
then
2638-
exists(Typ nt | nt = node.getDataFlowType() |
2639-
if typeStrongerThan(nt, t0) then t = nt else (compatibleTypes(nt, t0) and t = t0)
2640-
)
2641-
else t = t0
2642-
) and
2639+
strengthenType(node, t0, t) and
26432640
exists(state) and
26442641
exists(ap)
26452642
}
@@ -3373,14 +3370,7 @@ module Impl<FullStateConfigSig Config> {
33733370
exists(DataFlowType t0 |
33743371
pathStep0(mid, node, state, cc, sc, t0, ap) and
33753372
Stage5::revFlow(node, state, ap.getApprox()) and
3376-
(
3377-
if castingNodeEx(node)
3378-
then
3379-
exists(DataFlowType nt | nt = node.getDataFlowType() |
3380-
if typeStrongerThan(nt, t0) then t = nt else (compatibleTypes(nt, t0) and t = t0)
3381-
)
3382-
else t = t0
3383-
)
3373+
strengthenType(node, t0, t)
33843374
)
33853375
}
33863376

@@ -4055,12 +4045,7 @@ module Impl<FullStateConfigSig Config> {
40554045
notExpectsContent(node) or
40564046
expectsContentEx(node, ap.getHead())
40574047
) and
4058-
if castingNodeEx(node)
4059-
then
4060-
exists(DataFlowType nt | nt = node.getDataFlowType() |
4061-
if typeStrongerThan(nt, t0) then t = nt else (compatibleTypes(nt, t0) and t = t0)
4062-
)
4063-
else t = t0
4048+
strengthenType(node, t0, t)
40644049
}
40654050

40664051
pragma[nomagic]

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

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,7 @@ module Impl<FullStateConfigSig Config> {
12111211
filter(node, state, t0, ap, t)
12121212
}
12131213

1214+
pragma[nomagic]
12141215
private predicate typeStrengthen(Typ t0, Ap ap, Typ t) {
12151216
fwdFlow1(_, _, _, _, _, _, t0, t, ap, _) and t0 != t
12161217
}
@@ -2255,6 +2256,16 @@ module Impl<FullStateConfigSig Config> {
22552256
import MkStage<Stage2>::Stage<Stage3Param>
22562257
}
22572258

2259+
bindingset[node, t0]
2260+
private predicate strengthenType(NodeEx node, DataFlowType t0, DataFlowType t) {
2261+
if castingNodeEx(node)
2262+
then
2263+
exists(DataFlowType nt | nt = node.getDataFlowType() |
2264+
if typeStrongerThan(nt, t0) then t = nt else (compatibleTypes(nt, t0) and t = t0)
2265+
)
2266+
else t = t0
2267+
}
2268+
22582269
private module Stage4Param implements MkStage<Stage3>::StageParam {
22592270
private module PrevStage = Stage3;
22602271

@@ -2351,14 +2362,7 @@ module Impl<FullStateConfigSig Config> {
23512362
predicate filter(NodeEx node, FlowState state, Typ t0, Ap ap, Typ t) {
23522363
exists(state) and
23532364
not clear(node, ap) and
2354-
(
2355-
if castingNodeEx(node)
2356-
then
2357-
exists(Typ nt | nt = node.getDataFlowType() |
2358-
if typeStrongerThan(nt, t0) then t = nt else (compatibleTypes(nt, t0) and t = t0)
2359-
)
2360-
else t = t0
2361-
) and
2365+
strengthenType(node, t0, t) and
23622366
(
23632367
notExpectsContent(node)
23642368
or
@@ -2632,14 +2636,7 @@ module Impl<FullStateConfigSig Config> {
26322636

26332637
bindingset[node, state, t0, ap]
26342638
predicate filter(NodeEx node, FlowState state, Typ t0, Ap ap, Typ t) {
2635-
(
2636-
if castingNodeEx(node)
2637-
then
2638-
exists(Typ nt | nt = node.getDataFlowType() |
2639-
if typeStrongerThan(nt, t0) then t = nt else (compatibleTypes(nt, t0) and t = t0)
2640-
)
2641-
else t = t0
2642-
) and
2639+
strengthenType(node, t0, t) and
26432640
exists(state) and
26442641
exists(ap)
26452642
}
@@ -3373,14 +3370,7 @@ module Impl<FullStateConfigSig Config> {
33733370
exists(DataFlowType t0 |
33743371
pathStep0(mid, node, state, cc, sc, t0, ap) and
33753372
Stage5::revFlow(node, state, ap.getApprox()) and
3376-
(
3377-
if castingNodeEx(node)
3378-
then
3379-
exists(DataFlowType nt | nt = node.getDataFlowType() |
3380-
if typeStrongerThan(nt, t0) then t = nt else (compatibleTypes(nt, t0) and t = t0)
3381-
)
3382-
else t = t0
3383-
)
3373+
strengthenType(node, t0, t)
33843374
)
33853375
}
33863376

@@ -4055,12 +4045,7 @@ module Impl<FullStateConfigSig Config> {
40554045
notExpectsContent(node) or
40564046
expectsContentEx(node, ap.getHead())
40574047
) and
4058-
if castingNodeEx(node)
4059-
then
4060-
exists(DataFlowType nt | nt = node.getDataFlowType() |
4061-
if typeStrongerThan(nt, t0) then t = nt else (compatibleTypes(nt, t0) and t = t0)
4062-
)
4063-
else t = t0
4048+
strengthenType(node, t0, t)
40644049
}
40654050

40664051
pragma[nomagic]

go/ql/lib/semmle/go/dataflow/internal/DataFlowImpl.qll

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,7 @@ module Impl<FullStateConfigSig Config> {
12111211
filter(node, state, t0, ap, t)
12121212
}
12131213

1214+
pragma[nomagic]
12141215
private predicate typeStrengthen(Typ t0, Ap ap, Typ t) {
12151216
fwdFlow1(_, _, _, _, _, _, t0, t, ap, _) and t0 != t
12161217
}
@@ -2255,6 +2256,16 @@ module Impl<FullStateConfigSig Config> {
22552256
import MkStage<Stage2>::Stage<Stage3Param>
22562257
}
22572258

2259+
bindingset[node, t0]
2260+
private predicate strengthenType(NodeEx node, DataFlowType t0, DataFlowType t) {
2261+
if castingNodeEx(node)
2262+
then
2263+
exists(DataFlowType nt | nt = node.getDataFlowType() |
2264+
if typeStrongerThan(nt, t0) then t = nt else (compatibleTypes(nt, t0) and t = t0)
2265+
)
2266+
else t = t0
2267+
}
2268+
22582269
private module Stage4Param implements MkStage<Stage3>::StageParam {
22592270
private module PrevStage = Stage3;
22602271

@@ -2351,14 +2362,7 @@ module Impl<FullStateConfigSig Config> {
23512362
predicate filter(NodeEx node, FlowState state, Typ t0, Ap ap, Typ t) {
23522363
exists(state) and
23532364
not clear(node, ap) and
2354-
(
2355-
if castingNodeEx(node)
2356-
then
2357-
exists(Typ nt | nt = node.getDataFlowType() |
2358-
if typeStrongerThan(nt, t0) then t = nt else (compatibleTypes(nt, t0) and t = t0)
2359-
)
2360-
else t = t0
2361-
) and
2365+
strengthenType(node, t0, t) and
23622366
(
23632367
notExpectsContent(node)
23642368
or
@@ -2632,14 +2636,7 @@ module Impl<FullStateConfigSig Config> {
26322636

26332637
bindingset[node, state, t0, ap]
26342638
predicate filter(NodeEx node, FlowState state, Typ t0, Ap ap, Typ t) {
2635-
(
2636-
if castingNodeEx(node)
2637-
then
2638-
exists(Typ nt | nt = node.getDataFlowType() |
2639-
if typeStrongerThan(nt, t0) then t = nt else (compatibleTypes(nt, t0) and t = t0)
2640-
)
2641-
else t = t0
2642-
) and
2639+
strengthenType(node, t0, t) and
26432640
exists(state) and
26442641
exists(ap)
26452642
}
@@ -3373,14 +3370,7 @@ module Impl<FullStateConfigSig Config> {
33733370
exists(DataFlowType t0 |
33743371
pathStep0(mid, node, state, cc, sc, t0, ap) and
33753372
Stage5::revFlow(node, state, ap.getApprox()) and
3376-
(
3377-
if castingNodeEx(node)
3378-
then
3379-
exists(DataFlowType nt | nt = node.getDataFlowType() |
3380-
if typeStrongerThan(nt, t0) then t = nt else (compatibleTypes(nt, t0) and t = t0)
3381-
)
3382-
else t = t0
3383-
)
3373+
strengthenType(node, t0, t)
33843374
)
33853375
}
33863376

@@ -4055,12 +4045,7 @@ module Impl<FullStateConfigSig Config> {
40554045
notExpectsContent(node) or
40564046
expectsContentEx(node, ap.getHead())
40574047
) and
4058-
if castingNodeEx(node)
4059-
then
4060-
exists(DataFlowType nt | nt = node.getDataFlowType() |
4061-
if typeStrongerThan(nt, t0) then t = nt else (compatibleTypes(nt, t0) and t = t0)
4062-
)
4063-
else t = t0
4048+
strengthenType(node, t0, t)
40644049
}
40654050

40664051
pragma[nomagic]

0 commit comments

Comments
 (0)