Skip to content

Commit 446c738

Browse files
authored
Merge pull request #6790 from aschackmull/dataflow/force-precision
Dataflow: Force high precision of certain Contents.
2 parents 951df38 + 1bec58d commit 446c738

35 files changed

+342
-175
lines changed

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,7 +2139,8 @@ private predicate expensiveLen2unfolding(TypedContent tc, Configuration config)
21392139
) and
21402140
accessPathApproxCostLimits(apLimit, tupleLimit) and
21412141
apLimit < tails and
2142-
tupleLimit < (tails - 1) * nodes
2142+
tupleLimit < (tails - 1) * nodes and
2143+
not tc.forceHighPrecision()
21432144
)
21442145
}
21452146

@@ -2973,12 +2974,15 @@ private AccessPathApprox getATail(AccessPathApprox apa, Configuration config) {
29732974
* expected to be expensive. Holds with `unfold = true` otherwise.
29742975
*/
29752976
private predicate evalUnfold(AccessPathApprox apa, boolean unfold, Configuration config) {
2976-
exists(int aps, int nodes, int apLimit, int tupleLimit |
2977-
aps = countPotentialAps(apa, config) and
2978-
nodes = countNodesUsingAccessPath(apa, config) and
2979-
accessPathCostLimits(apLimit, tupleLimit) and
2980-
if apLimit < aps and tupleLimit < (aps - 1) * nodes then unfold = false else unfold = true
2981-
)
2977+
if apa.getHead().forceHighPrecision()
2978+
then unfold = true
2979+
else
2980+
exists(int aps, int nodes, int apLimit, int tupleLimit |
2981+
aps = countPotentialAps(apa, config) and
2982+
nodes = countNodesUsingAccessPath(apa, config) and
2983+
accessPathCostLimits(apLimit, tupleLimit) and
2984+
if apLimit < aps and tupleLimit < (aps - 1) * nodes then unfold = false else unfold = true
2985+
)
29822986
}
29832987

29842988
/**

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,7 +2139,8 @@ private predicate expensiveLen2unfolding(TypedContent tc, Configuration config)
21392139
) and
21402140
accessPathApproxCostLimits(apLimit, tupleLimit) and
21412141
apLimit < tails and
2142-
tupleLimit < (tails - 1) * nodes
2142+
tupleLimit < (tails - 1) * nodes and
2143+
not tc.forceHighPrecision()
21432144
)
21442145
}
21452146

@@ -2973,12 +2974,15 @@ private AccessPathApprox getATail(AccessPathApprox apa, Configuration config) {
29732974
* expected to be expensive. Holds with `unfold = true` otherwise.
29742975
*/
29752976
private predicate evalUnfold(AccessPathApprox apa, boolean unfold, Configuration config) {
2976-
exists(int aps, int nodes, int apLimit, int tupleLimit |
2977-
aps = countPotentialAps(apa, config) and
2978-
nodes = countNodesUsingAccessPath(apa, config) and
2979-
accessPathCostLimits(apLimit, tupleLimit) and
2980-
if apLimit < aps and tupleLimit < (aps - 1) * nodes then unfold = false else unfold = true
2981-
)
2977+
if apa.getHead().forceHighPrecision()
2978+
then unfold = true
2979+
else
2980+
exists(int aps, int nodes, int apLimit, int tupleLimit |
2981+
aps = countPotentialAps(apa, config) and
2982+
nodes = countNodesUsingAccessPath(apa, config) and
2983+
accessPathCostLimits(apLimit, tupleLimit) and
2984+
if apLimit < aps and tupleLimit < (aps - 1) * nodes then unfold = false else unfold = true
2985+
)
29822986
}
29832987

29842988
/**

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,7 +2139,8 @@ private predicate expensiveLen2unfolding(TypedContent tc, Configuration config)
21392139
) and
21402140
accessPathApproxCostLimits(apLimit, tupleLimit) and
21412141
apLimit < tails and
2142-
tupleLimit < (tails - 1) * nodes
2142+
tupleLimit < (tails - 1) * nodes and
2143+
not tc.forceHighPrecision()
21432144
)
21442145
}
21452146

@@ -2973,12 +2974,15 @@ private AccessPathApprox getATail(AccessPathApprox apa, Configuration config) {
29732974
* expected to be expensive. Holds with `unfold = true` otherwise.
29742975
*/
29752976
private predicate evalUnfold(AccessPathApprox apa, boolean unfold, Configuration config) {
2976-
exists(int aps, int nodes, int apLimit, int tupleLimit |
2977-
aps = countPotentialAps(apa, config) and
2978-
nodes = countNodesUsingAccessPath(apa, config) and
2979-
accessPathCostLimits(apLimit, tupleLimit) and
2980-
if apLimit < aps and tupleLimit < (aps - 1) * nodes then unfold = false else unfold = true
2981-
)
2977+
if apa.getHead().forceHighPrecision()
2978+
then unfold = true
2979+
else
2980+
exists(int aps, int nodes, int apLimit, int tupleLimit |
2981+
aps = countPotentialAps(apa, config) and
2982+
nodes = countNodesUsingAccessPath(apa, config) and
2983+
accessPathCostLimits(apLimit, tupleLimit) and
2984+
if apLimit < aps and tupleLimit < (aps - 1) * nodes then unfold = false else unfold = true
2985+
)
29822986
}
29832987

29842988
/**

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,7 +2139,8 @@ private predicate expensiveLen2unfolding(TypedContent tc, Configuration config)
21392139
) and
21402140
accessPathApproxCostLimits(apLimit, tupleLimit) and
21412141
apLimit < tails and
2142-
tupleLimit < (tails - 1) * nodes
2142+
tupleLimit < (tails - 1) * nodes and
2143+
not tc.forceHighPrecision()
21432144
)
21442145
}
21452146

@@ -2973,12 +2974,15 @@ private AccessPathApprox getATail(AccessPathApprox apa, Configuration config) {
29732974
* expected to be expensive. Holds with `unfold = true` otherwise.
29742975
*/
29752976
private predicate evalUnfold(AccessPathApprox apa, boolean unfold, Configuration config) {
2976-
exists(int aps, int nodes, int apLimit, int tupleLimit |
2977-
aps = countPotentialAps(apa, config) and
2978-
nodes = countNodesUsingAccessPath(apa, config) and
2979-
accessPathCostLimits(apLimit, tupleLimit) and
2980-
if apLimit < aps and tupleLimit < (aps - 1) * nodes then unfold = false else unfold = true
2981-
)
2977+
if apa.getHead().forceHighPrecision()
2978+
then unfold = true
2979+
else
2980+
exists(int aps, int nodes, int apLimit, int tupleLimit |
2981+
aps = countPotentialAps(apa, config) and
2982+
nodes = countNodesUsingAccessPath(apa, config) and
2983+
accessPathCostLimits(apLimit, tupleLimit) and
2984+
if apLimit < aps and tupleLimit < (aps - 1) * nodes then unfold = false else unfold = true
2985+
)
29822986
}
29832987

29842988
/**

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,6 +1236,13 @@ class TypedContent extends MkTypedContent {
12361236

12371237
/** Gets a textual representation of this content. */
12381238
string toString() { result = c.toString() }
1239+
1240+
/**
1241+
* Holds if access paths with this `TypedContent` at their head always should
1242+
* be tracked at high precision. This disables adaptive access path precision
1243+
* for such access paths.
1244+
*/
1245+
predicate forceHighPrecision() { forceHighPrecision(c) }
12391246
}
12401247

12411248
/**

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,7 +2139,8 @@ private predicate expensiveLen2unfolding(TypedContent tc, Configuration config)
21392139
) and
21402140
accessPathApproxCostLimits(apLimit, tupleLimit) and
21412141
apLimit < tails and
2142-
tupleLimit < (tails - 1) * nodes
2142+
tupleLimit < (tails - 1) * nodes and
2143+
not tc.forceHighPrecision()
21432144
)
21442145
}
21452146

@@ -2973,12 +2974,15 @@ private AccessPathApprox getATail(AccessPathApprox apa, Configuration config) {
29732974
* expected to be expensive. Holds with `unfold = true` otherwise.
29742975
*/
29752976
private predicate evalUnfold(AccessPathApprox apa, boolean unfold, Configuration config) {
2976-
exists(int aps, int nodes, int apLimit, int tupleLimit |
2977-
aps = countPotentialAps(apa, config) and
2978-
nodes = countNodesUsingAccessPath(apa, config) and
2979-
accessPathCostLimits(apLimit, tupleLimit) and
2980-
if apLimit < aps and tupleLimit < (aps - 1) * nodes then unfold = false else unfold = true
2981-
)
2977+
if apa.getHead().forceHighPrecision()
2978+
then unfold = true
2979+
else
2980+
exists(int aps, int nodes, int apLimit, int tupleLimit |
2981+
aps = countPotentialAps(apa, config) and
2982+
nodes = countNodesUsingAccessPath(apa, config) and
2983+
accessPathCostLimits(apLimit, tupleLimit) and
2984+
if apLimit < aps and tupleLimit < (aps - 1) * nodes then unfold = false else unfold = true
2985+
)
29822986
}
29832987

29842988
/**

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,12 @@ predicate isUnreachableInCall(Node n, DataFlowCall call) { none() } // stub impl
240240

241241
int accessPathLimit() { result = 5 }
242242

243+
/**
244+
* Holds if access paths with `c` at their head always should be tracked at high
245+
* precision. This disables adaptive access path precision for such access paths.
246+
*/
247+
predicate forceHighPrecision(Content c) { none() }
248+
243249
/** The unit type. */
244250
private newtype TUnit = TMkUnit()
245251

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,7 +2139,8 @@ private predicate expensiveLen2unfolding(TypedContent tc, Configuration config)
21392139
) and
21402140
accessPathApproxCostLimits(apLimit, tupleLimit) and
21412141
apLimit < tails and
2142-
tupleLimit < (tails - 1) * nodes
2142+
tupleLimit < (tails - 1) * nodes and
2143+
not tc.forceHighPrecision()
21432144
)
21442145
}
21452146

@@ -2973,12 +2974,15 @@ private AccessPathApprox getATail(AccessPathApprox apa, Configuration config) {
29732974
* expected to be expensive. Holds with `unfold = true` otherwise.
29742975
*/
29752976
private predicate evalUnfold(AccessPathApprox apa, boolean unfold, Configuration config) {
2976-
exists(int aps, int nodes, int apLimit, int tupleLimit |
2977-
aps = countPotentialAps(apa, config) and
2978-
nodes = countNodesUsingAccessPath(apa, config) and
2979-
accessPathCostLimits(apLimit, tupleLimit) and
2980-
if apLimit < aps and tupleLimit < (aps - 1) * nodes then unfold = false else unfold = true
2981-
)
2977+
if apa.getHead().forceHighPrecision()
2978+
then unfold = true
2979+
else
2980+
exists(int aps, int nodes, int apLimit, int tupleLimit |
2981+
aps = countPotentialAps(apa, config) and
2982+
nodes = countNodesUsingAccessPath(apa, config) and
2983+
accessPathCostLimits(apLimit, tupleLimit) and
2984+
if apLimit < aps and tupleLimit < (aps - 1) * nodes then unfold = false else unfold = true
2985+
)
29822986
}
29832987

29842988
/**

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,7 +2139,8 @@ private predicate expensiveLen2unfolding(TypedContent tc, Configuration config)
21392139
) and
21402140
accessPathApproxCostLimits(apLimit, tupleLimit) and
21412141
apLimit < tails and
2142-
tupleLimit < (tails - 1) * nodes
2142+
tupleLimit < (tails - 1) * nodes and
2143+
not tc.forceHighPrecision()
21432144
)
21442145
}
21452146

@@ -2973,12 +2974,15 @@ private AccessPathApprox getATail(AccessPathApprox apa, Configuration config) {
29732974
* expected to be expensive. Holds with `unfold = true` otherwise.
29742975
*/
29752976
private predicate evalUnfold(AccessPathApprox apa, boolean unfold, Configuration config) {
2976-
exists(int aps, int nodes, int apLimit, int tupleLimit |
2977-
aps = countPotentialAps(apa, config) and
2978-
nodes = countNodesUsingAccessPath(apa, config) and
2979-
accessPathCostLimits(apLimit, tupleLimit) and
2980-
if apLimit < aps and tupleLimit < (aps - 1) * nodes then unfold = false else unfold = true
2981-
)
2977+
if apa.getHead().forceHighPrecision()
2978+
then unfold = true
2979+
else
2980+
exists(int aps, int nodes, int apLimit, int tupleLimit |
2981+
aps = countPotentialAps(apa, config) and
2982+
nodes = countNodesUsingAccessPath(apa, config) and
2983+
accessPathCostLimits(apLimit, tupleLimit) and
2984+
if apLimit < aps and tupleLimit < (aps - 1) * nodes then unfold = false else unfold = true
2985+
)
29822986
}
29832987

29842988
/**

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,7 +2139,8 @@ private predicate expensiveLen2unfolding(TypedContent tc, Configuration config)
21392139
) and
21402140
accessPathApproxCostLimits(apLimit, tupleLimit) and
21412141
apLimit < tails and
2142-
tupleLimit < (tails - 1) * nodes
2142+
tupleLimit < (tails - 1) * nodes and
2143+
not tc.forceHighPrecision()
21432144
)
21442145
}
21452146

@@ -2973,12 +2974,15 @@ private AccessPathApprox getATail(AccessPathApprox apa, Configuration config) {
29732974
* expected to be expensive. Holds with `unfold = true` otherwise.
29742975
*/
29752976
private predicate evalUnfold(AccessPathApprox apa, boolean unfold, Configuration config) {
2976-
exists(int aps, int nodes, int apLimit, int tupleLimit |
2977-
aps = countPotentialAps(apa, config) and
2978-
nodes = countNodesUsingAccessPath(apa, config) and
2979-
accessPathCostLimits(apLimit, tupleLimit) and
2980-
if apLimit < aps and tupleLimit < (aps - 1) * nodes then unfold = false else unfold = true
2981-
)
2977+
if apa.getHead().forceHighPrecision()
2978+
then unfold = true
2979+
else
2980+
exists(int aps, int nodes, int apLimit, int tupleLimit |
2981+
aps = countPotentialAps(apa, config) and
2982+
nodes = countNodesUsingAccessPath(apa, config) and
2983+
accessPathCostLimits(apLimit, tupleLimit) and
2984+
if apLimit < aps and tupleLimit < (aps - 1) * nodes then unfold = false else unfold = true
2985+
)
29822986
}
29832987

29842988
/**

0 commit comments

Comments
 (0)