Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b352605

Browse files
committed
Dataflow: Code review fixes.
1 parent 664f040 commit b352605

21 files changed

Lines changed: 231 additions & 336 deletions

File tree

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

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,7 @@ private predicate expensiveLen2unfolding(TypedContent tc, Configuration config)
15461546
strictcount(Node n |
15471547
flowCand(n, _, _, any(AccessPathFrontHead apf | apf.headUsesContent(tc)), config)
15481548
or
1549-
flowCandSummaryCtx(n, any(AccessPathFrontHead apf | apf.headUsesContent(tc)), _)
1549+
flowCandSummaryCtx(n, any(AccessPathFrontHead apf | apf.headUsesContent(tc)), config)
15501550
) and
15511551
accessPathApproxCostLimits(apLimit, tupleLimit) and
15521552
apLimit < tails and
@@ -2144,11 +2144,12 @@ private predicate parameterMayFlowThrough(ParameterNode p, DataFlowCallable c, A
21442144
)
21452145
}
21462146

2147-
private predicate nodeMayUseSummary(Node n, AccessPathApprox apa) {
2147+
private predicate nodeMayUseSummary(Node n, AccessPathApprox apa, Configuration config) {
21482148
exists(DataFlowCallable c, AccessPathApprox apa0 |
21492149
parameterMayFlowThrough(_, c, apa) and
2150-
flow(n, true, _, apa0, _) and
2151-
flowFwd(n, any(CallContextCall ccc), TAccessPathApproxSome(apa), _, apa0, _)
2150+
flow(n, true, _, apa0, config) and
2151+
flowFwd(n, any(CallContextCall ccc), TAccessPathApproxSome(apa), _, apa0, config) and
2152+
n.getEnclosingCallable() = c
21522153
)
21532154
}
21542155

@@ -2204,19 +2205,18 @@ private int count1to2unfold(AccessPathApproxCons1 apa, Configuration config) {
22042205
)
22052206
}
22062207

2208+
private int countNodesUsingAccessPath(AccessPathApprox apa, Configuration config) {
2209+
result = strictcount(Node n | flow(n, _, _, apa, config) or nodeMayUseSummary(n, apa, config))
2210+
}
2211+
22072212
/**
22082213
* Holds if a length 2 access path approximation matching `apa` is expected
22092214
* to be expensive.
22102215
*/
22112216
private predicate expensiveLen1to2unfolding(AccessPathApproxCons1 apa, Configuration config) {
22122217
exists(int aps, int nodes, int apLimit, int tupleLimit |
22132218
aps = count1to2unfold(apa, config) and
2214-
nodes =
2215-
strictcount(Node n |
2216-
flow(n, _, _, apa, config)
2217-
or
2218-
nodeMayUseSummary(n, apa)
2219-
) and
2219+
nodes = countNodesUsingAccessPath(apa, config) and
22202220
accessPathCostLimits(apLimit, tupleLimit) and
22212221
apLimit < aps and
22222222
tupleLimit < (aps - 1) * nodes
@@ -2237,12 +2237,7 @@ private AccessPathApprox getATail(AccessPathApprox apa, Configuration config) {
22372237
private predicate evalUnfold(AccessPathApprox apa, boolean unfold, Configuration config) {
22382238
exists(int aps, int nodes, int apLimit, int tupleLimit |
22392239
aps = countPotentialAps(apa, config) and
2240-
nodes =
2241-
strictcount(Node n |
2242-
flow(n, _, _, apa, _)
2243-
or
2244-
nodeMayUseSummary(n, apa)
2245-
) and
2240+
nodes = countNodesUsingAccessPath(apa, config) and
22462241
accessPathCostLimits(apLimit, tupleLimit) and
22472242
if apLimit < aps and tupleLimit < (aps - 1) * nodes then unfold = false else unfold = true
22482243
)

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

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,7 @@ private predicate expensiveLen2unfolding(TypedContent tc, Configuration config)
15461546
strictcount(Node n |
15471547
flowCand(n, _, _, any(AccessPathFrontHead apf | apf.headUsesContent(tc)), config)
15481548
or
1549-
flowCandSummaryCtx(n, any(AccessPathFrontHead apf | apf.headUsesContent(tc)), _)
1549+
flowCandSummaryCtx(n, any(AccessPathFrontHead apf | apf.headUsesContent(tc)), config)
15501550
) and
15511551
accessPathApproxCostLimits(apLimit, tupleLimit) and
15521552
apLimit < tails and
@@ -2144,11 +2144,12 @@ private predicate parameterMayFlowThrough(ParameterNode p, DataFlowCallable c, A
21442144
)
21452145
}
21462146

2147-
private predicate nodeMayUseSummary(Node n, AccessPathApprox apa) {
2147+
private predicate nodeMayUseSummary(Node n, AccessPathApprox apa, Configuration config) {
21482148
exists(DataFlowCallable c, AccessPathApprox apa0 |
21492149
parameterMayFlowThrough(_, c, apa) and
2150-
flow(n, true, _, apa0, _) and
2151-
flowFwd(n, any(CallContextCall ccc), TAccessPathApproxSome(apa), _, apa0, _)
2150+
flow(n, true, _, apa0, config) and
2151+
flowFwd(n, any(CallContextCall ccc), TAccessPathApproxSome(apa), _, apa0, config) and
2152+
n.getEnclosingCallable() = c
21522153
)
21532154
}
21542155

@@ -2204,19 +2205,18 @@ private int count1to2unfold(AccessPathApproxCons1 apa, Configuration config) {
22042205
)
22052206
}
22062207

2208+
private int countNodesUsingAccessPath(AccessPathApprox apa, Configuration config) {
2209+
result = strictcount(Node n | flow(n, _, _, apa, config) or nodeMayUseSummary(n, apa, config))
2210+
}
2211+
22072212
/**
22082213
* Holds if a length 2 access path approximation matching `apa` is expected
22092214
* to be expensive.
22102215
*/
22112216
private predicate expensiveLen1to2unfolding(AccessPathApproxCons1 apa, Configuration config) {
22122217
exists(int aps, int nodes, int apLimit, int tupleLimit |
22132218
aps = count1to2unfold(apa, config) and
2214-
nodes =
2215-
strictcount(Node n |
2216-
flow(n, _, _, apa, config)
2217-
or
2218-
nodeMayUseSummary(n, apa)
2219-
) and
2219+
nodes = countNodesUsingAccessPath(apa, config) and
22202220
accessPathCostLimits(apLimit, tupleLimit) and
22212221
apLimit < aps and
22222222
tupleLimit < (aps - 1) * nodes
@@ -2237,12 +2237,7 @@ private AccessPathApprox getATail(AccessPathApprox apa, Configuration config) {
22372237
private predicate evalUnfold(AccessPathApprox apa, boolean unfold, Configuration config) {
22382238
exists(int aps, int nodes, int apLimit, int tupleLimit |
22392239
aps = countPotentialAps(apa, config) and
2240-
nodes =
2241-
strictcount(Node n |
2242-
flow(n, _, _, apa, _)
2243-
or
2244-
nodeMayUseSummary(n, apa)
2245-
) and
2240+
nodes = countNodesUsingAccessPath(apa, config) and
22462241
accessPathCostLimits(apLimit, tupleLimit) and
22472242
if apLimit < aps and tupleLimit < (aps - 1) * nodes then unfold = false else unfold = true
22482243
)

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

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,7 @@ private predicate expensiveLen2unfolding(TypedContent tc, Configuration config)
15461546
strictcount(Node n |
15471547
flowCand(n, _, _, any(AccessPathFrontHead apf | apf.headUsesContent(tc)), config)
15481548
or
1549-
flowCandSummaryCtx(n, any(AccessPathFrontHead apf | apf.headUsesContent(tc)), _)
1549+
flowCandSummaryCtx(n, any(AccessPathFrontHead apf | apf.headUsesContent(tc)), config)
15501550
) and
15511551
accessPathApproxCostLimits(apLimit, tupleLimit) and
15521552
apLimit < tails and
@@ -2144,11 +2144,12 @@ private predicate parameterMayFlowThrough(ParameterNode p, DataFlowCallable c, A
21442144
)
21452145
}
21462146

2147-
private predicate nodeMayUseSummary(Node n, AccessPathApprox apa) {
2147+
private predicate nodeMayUseSummary(Node n, AccessPathApprox apa, Configuration config) {
21482148
exists(DataFlowCallable c, AccessPathApprox apa0 |
21492149
parameterMayFlowThrough(_, c, apa) and
2150-
flow(n, true, _, apa0, _) and
2151-
flowFwd(n, any(CallContextCall ccc), TAccessPathApproxSome(apa), _, apa0, _)
2150+
flow(n, true, _, apa0, config) and
2151+
flowFwd(n, any(CallContextCall ccc), TAccessPathApproxSome(apa), _, apa0, config) and
2152+
n.getEnclosingCallable() = c
21522153
)
21532154
}
21542155

@@ -2204,19 +2205,18 @@ private int count1to2unfold(AccessPathApproxCons1 apa, Configuration config) {
22042205
)
22052206
}
22062207

2208+
private int countNodesUsingAccessPath(AccessPathApprox apa, Configuration config) {
2209+
result = strictcount(Node n | flow(n, _, _, apa, config) or nodeMayUseSummary(n, apa, config))
2210+
}
2211+
22072212
/**
22082213
* Holds if a length 2 access path approximation matching `apa` is expected
22092214
* to be expensive.
22102215
*/
22112216
private predicate expensiveLen1to2unfolding(AccessPathApproxCons1 apa, Configuration config) {
22122217
exists(int aps, int nodes, int apLimit, int tupleLimit |
22132218
aps = count1to2unfold(apa, config) and
2214-
nodes =
2215-
strictcount(Node n |
2216-
flow(n, _, _, apa, config)
2217-
or
2218-
nodeMayUseSummary(n, apa)
2219-
) and
2219+
nodes = countNodesUsingAccessPath(apa, config) and
22202220
accessPathCostLimits(apLimit, tupleLimit) and
22212221
apLimit < aps and
22222222
tupleLimit < (aps - 1) * nodes
@@ -2237,12 +2237,7 @@ private AccessPathApprox getATail(AccessPathApprox apa, Configuration config) {
22372237
private predicate evalUnfold(AccessPathApprox apa, boolean unfold, Configuration config) {
22382238
exists(int aps, int nodes, int apLimit, int tupleLimit |
22392239
aps = countPotentialAps(apa, config) and
2240-
nodes =
2241-
strictcount(Node n |
2242-
flow(n, _, _, apa, _)
2243-
or
2244-
nodeMayUseSummary(n, apa)
2245-
) and
2240+
nodes = countNodesUsingAccessPath(apa, config) and
22462241
accessPathCostLimits(apLimit, tupleLimit) and
22472242
if apLimit < aps and tupleLimit < (aps - 1) * nodes then unfold = false else unfold = true
22482243
)

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

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,7 @@ private predicate expensiveLen2unfolding(TypedContent tc, Configuration config)
15461546
strictcount(Node n |
15471547
flowCand(n, _, _, any(AccessPathFrontHead apf | apf.headUsesContent(tc)), config)
15481548
or
1549-
flowCandSummaryCtx(n, any(AccessPathFrontHead apf | apf.headUsesContent(tc)), _)
1549+
flowCandSummaryCtx(n, any(AccessPathFrontHead apf | apf.headUsesContent(tc)), config)
15501550
) and
15511551
accessPathApproxCostLimits(apLimit, tupleLimit) and
15521552
apLimit < tails and
@@ -2144,11 +2144,12 @@ private predicate parameterMayFlowThrough(ParameterNode p, DataFlowCallable c, A
21442144
)
21452145
}
21462146

2147-
private predicate nodeMayUseSummary(Node n, AccessPathApprox apa) {
2147+
private predicate nodeMayUseSummary(Node n, AccessPathApprox apa, Configuration config) {
21482148
exists(DataFlowCallable c, AccessPathApprox apa0 |
21492149
parameterMayFlowThrough(_, c, apa) and
2150-
flow(n, true, _, apa0, _) and
2151-
flowFwd(n, any(CallContextCall ccc), TAccessPathApproxSome(apa), _, apa0, _)
2150+
flow(n, true, _, apa0, config) and
2151+
flowFwd(n, any(CallContextCall ccc), TAccessPathApproxSome(apa), _, apa0, config) and
2152+
n.getEnclosingCallable() = c
21522153
)
21532154
}
21542155

@@ -2204,19 +2205,18 @@ private int count1to2unfold(AccessPathApproxCons1 apa, Configuration config) {
22042205
)
22052206
}
22062207

2208+
private int countNodesUsingAccessPath(AccessPathApprox apa, Configuration config) {
2209+
result = strictcount(Node n | flow(n, _, _, apa, config) or nodeMayUseSummary(n, apa, config))
2210+
}
2211+
22072212
/**
22082213
* Holds if a length 2 access path approximation matching `apa` is expected
22092214
* to be expensive.
22102215
*/
22112216
private predicate expensiveLen1to2unfolding(AccessPathApproxCons1 apa, Configuration config) {
22122217
exists(int aps, int nodes, int apLimit, int tupleLimit |
22132218
aps = count1to2unfold(apa, config) and
2214-
nodes =
2215-
strictcount(Node n |
2216-
flow(n, _, _, apa, config)
2217-
or
2218-
nodeMayUseSummary(n, apa)
2219-
) and
2219+
nodes = countNodesUsingAccessPath(apa, config) and
22202220
accessPathCostLimits(apLimit, tupleLimit) and
22212221
apLimit < aps and
22222222
tupleLimit < (aps - 1) * nodes
@@ -2237,12 +2237,7 @@ private AccessPathApprox getATail(AccessPathApprox apa, Configuration config) {
22372237
private predicate evalUnfold(AccessPathApprox apa, boolean unfold, Configuration config) {
22382238
exists(int aps, int nodes, int apLimit, int tupleLimit |
22392239
aps = countPotentialAps(apa, config) and
2240-
nodes =
2241-
strictcount(Node n |
2242-
flow(n, _, _, apa, _)
2243-
or
2244-
nodeMayUseSummary(n, apa)
2245-
) and
2240+
nodes = countNodesUsingAccessPath(apa, config) and
22462241
accessPathCostLimits(apLimit, tupleLimit) and
22472242
if apLimit < aps and tupleLimit < (aps - 1) * nodes then unfold = false else unfold = true
22482243
)

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

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,7 @@ private predicate expensiveLen2unfolding(TypedContent tc, Configuration config)
15461546
strictcount(Node n |
15471547
flowCand(n, _, _, any(AccessPathFrontHead apf | apf.headUsesContent(tc)), config)
15481548
or
1549-
flowCandSummaryCtx(n, any(AccessPathFrontHead apf | apf.headUsesContent(tc)), _)
1549+
flowCandSummaryCtx(n, any(AccessPathFrontHead apf | apf.headUsesContent(tc)), config)
15501550
) and
15511551
accessPathApproxCostLimits(apLimit, tupleLimit) and
15521552
apLimit < tails and
@@ -2144,11 +2144,12 @@ private predicate parameterMayFlowThrough(ParameterNode p, DataFlowCallable c, A
21442144
)
21452145
}
21462146

2147-
private predicate nodeMayUseSummary(Node n, AccessPathApprox apa) {
2147+
private predicate nodeMayUseSummary(Node n, AccessPathApprox apa, Configuration config) {
21482148
exists(DataFlowCallable c, AccessPathApprox apa0 |
21492149
parameterMayFlowThrough(_, c, apa) and
2150-
flow(n, true, _, apa0, _) and
2151-
flowFwd(n, any(CallContextCall ccc), TAccessPathApproxSome(apa), _, apa0, _)
2150+
flow(n, true, _, apa0, config) and
2151+
flowFwd(n, any(CallContextCall ccc), TAccessPathApproxSome(apa), _, apa0, config) and
2152+
n.getEnclosingCallable() = c
21522153
)
21532154
}
21542155

@@ -2204,19 +2205,18 @@ private int count1to2unfold(AccessPathApproxCons1 apa, Configuration config) {
22042205
)
22052206
}
22062207

2208+
private int countNodesUsingAccessPath(AccessPathApprox apa, Configuration config) {
2209+
result = strictcount(Node n | flow(n, _, _, apa, config) or nodeMayUseSummary(n, apa, config))
2210+
}
2211+
22072212
/**
22082213
* Holds if a length 2 access path approximation matching `apa` is expected
22092214
* to be expensive.
22102215
*/
22112216
private predicate expensiveLen1to2unfolding(AccessPathApproxCons1 apa, Configuration config) {
22122217
exists(int aps, int nodes, int apLimit, int tupleLimit |
22132218
aps = count1to2unfold(apa, config) and
2214-
nodes =
2215-
strictcount(Node n |
2216-
flow(n, _, _, apa, config)
2217-
or
2218-
nodeMayUseSummary(n, apa)
2219-
) and
2219+
nodes = countNodesUsingAccessPath(apa, config) and
22202220
accessPathCostLimits(apLimit, tupleLimit) and
22212221
apLimit < aps and
22222222
tupleLimit < (aps - 1) * nodes
@@ -2237,12 +2237,7 @@ private AccessPathApprox getATail(AccessPathApprox apa, Configuration config) {
22372237
private predicate evalUnfold(AccessPathApprox apa, boolean unfold, Configuration config) {
22382238
exists(int aps, int nodes, int apLimit, int tupleLimit |
22392239
aps = countPotentialAps(apa, config) and
2240-
nodes =
2241-
strictcount(Node n |
2242-
flow(n, _, _, apa, _)
2243-
or
2244-
nodeMayUseSummary(n, apa)
2245-
) and
2240+
nodes = countNodesUsingAccessPath(apa, config) and
22462241
accessPathCostLimits(apLimit, tupleLimit) and
22472242
if apLimit < aps and tupleLimit < (aps - 1) * nodes then unfold = false else unfold = true
22482243
)

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

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,7 @@ private predicate expensiveLen2unfolding(TypedContent tc, Configuration config)
15461546
strictcount(Node n |
15471547
flowCand(n, _, _, any(AccessPathFrontHead apf | apf.headUsesContent(tc)), config)
15481548
or
1549-
flowCandSummaryCtx(n, any(AccessPathFrontHead apf | apf.headUsesContent(tc)), _)
1549+
flowCandSummaryCtx(n, any(AccessPathFrontHead apf | apf.headUsesContent(tc)), config)
15501550
) and
15511551
accessPathApproxCostLimits(apLimit, tupleLimit) and
15521552
apLimit < tails and
@@ -2144,11 +2144,12 @@ private predicate parameterMayFlowThrough(ParameterNode p, DataFlowCallable c, A
21442144
)
21452145
}
21462146

2147-
private predicate nodeMayUseSummary(Node n, AccessPathApprox apa) {
2147+
private predicate nodeMayUseSummary(Node n, AccessPathApprox apa, Configuration config) {
21482148
exists(DataFlowCallable c, AccessPathApprox apa0 |
21492149
parameterMayFlowThrough(_, c, apa) and
2150-
flow(n, true, _, apa0, _) and
2151-
flowFwd(n, any(CallContextCall ccc), TAccessPathApproxSome(apa), _, apa0, _)
2150+
flow(n, true, _, apa0, config) and
2151+
flowFwd(n, any(CallContextCall ccc), TAccessPathApproxSome(apa), _, apa0, config) and
2152+
n.getEnclosingCallable() = c
21522153
)
21532154
}
21542155

@@ -2204,19 +2205,18 @@ private int count1to2unfold(AccessPathApproxCons1 apa, Configuration config) {
22042205
)
22052206
}
22062207

2208+
private int countNodesUsingAccessPath(AccessPathApprox apa, Configuration config) {
2209+
result = strictcount(Node n | flow(n, _, _, apa, config) or nodeMayUseSummary(n, apa, config))
2210+
}
2211+
22072212
/**
22082213
* Holds if a length 2 access path approximation matching `apa` is expected
22092214
* to be expensive.
22102215
*/
22112216
private predicate expensiveLen1to2unfolding(AccessPathApproxCons1 apa, Configuration config) {
22122217
exists(int aps, int nodes, int apLimit, int tupleLimit |
22132218
aps = count1to2unfold(apa, config) and
2214-
nodes =
2215-
strictcount(Node n |
2216-
flow(n, _, _, apa, config)
2217-
or
2218-
nodeMayUseSummary(n, apa)
2219-
) and
2219+
nodes = countNodesUsingAccessPath(apa, config) and
22202220
accessPathCostLimits(apLimit, tupleLimit) and
22212221
apLimit < aps and
22222222
tupleLimit < (aps - 1) * nodes
@@ -2237,12 +2237,7 @@ private AccessPathApprox getATail(AccessPathApprox apa, Configuration config) {
22372237
private predicate evalUnfold(AccessPathApprox apa, boolean unfold, Configuration config) {
22382238
exists(int aps, int nodes, int apLimit, int tupleLimit |
22392239
aps = countPotentialAps(apa, config) and
2240-
nodes =
2241-
strictcount(Node n |
2242-
flow(n, _, _, apa, _)
2243-
or
2244-
nodeMayUseSummary(n, apa)
2245-
) and
2240+
nodes = countNodesUsingAccessPath(apa, config) and
22462241
accessPathCostLimits(apLimit, tupleLimit) and
22472242
if apLimit < aps and tupleLimit < (aps - 1) * nodes then unfold = false else unfold = true
22482243
)

0 commit comments

Comments
 (0)