mirror of
https://github.com/github/codeql.git
synced 2026-02-23 18:33:42 +01:00
C++: Include the actual number of lower/upper bounds for added context in expected files
This commit is contained in:
@@ -2180,6 +2180,16 @@ module SimpleRangeAnalysisInternal {
|
||||
|
||||
/** Gets the estimate of the number of bounds for `e`. */
|
||||
float estimateNrOfBounds(Expr e) { result = BoundsEstimate::nrOfBoundsExpr(e) }
|
||||
|
||||
/** Counts the numbers of lower bounds that are computed internally for `e`. */
|
||||
float countNrOfLowerBounds(Expr e) {
|
||||
result = strictcount(float lb | lb = getLowerBoundsImpl(e) | lb)
|
||||
}
|
||||
|
||||
/** Counts the numbers of upper bounds that are computed internally for `e`. */
|
||||
float countNrOfUpperBounds(Expr e) {
|
||||
result = strictcount(float ub | ub = getUpperBoundsImpl(e) | ub)
|
||||
}
|
||||
}
|
||||
|
||||
/** Provides predicates for debugging the simple range analysis library. */
|
||||
@@ -2208,7 +2218,7 @@ private module Debug {
|
||||
*/
|
||||
predicate countGetLowerBoundsImpl(Expr e, int n) {
|
||||
e = getRelevantLocatable() and
|
||||
n = strictcount(float lb | lb = getLowerBoundsImpl(e) | lb)
|
||||
n = SimpleRangeAnalysisInternal::countNrOfLowerBounds(e)
|
||||
}
|
||||
|
||||
float debugNrOfBounds(Expr e) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,8 +2,20 @@ import cpp
|
||||
import utils.test.InlineExpectationsTest
|
||||
import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis
|
||||
|
||||
query predicate estimateNrOfBounds(Expr e, float nrOfBounds) {
|
||||
nrOfBounds = SimpleRangeAnalysisInternal::estimateNrOfBounds(e)
|
||||
query predicate estimateNrOfBounds(
|
||||
Expr e, float nrOfBounds, float actualNrOfLowerBounds, float actualNrOfUpperBounds
|
||||
) {
|
||||
nrOfBounds = SimpleRangeAnalysisInternal::estimateNrOfBounds(e) and
|
||||
(
|
||||
actualNrOfLowerBounds = SimpleRangeAnalysisInternal::countNrOfLowerBounds(e)
|
||||
or
|
||||
not exists(SimpleRangeAnalysisInternal::countNrOfLowerBounds(e)) and actualNrOfLowerBounds = -1
|
||||
) and
|
||||
(
|
||||
actualNrOfUpperBounds = SimpleRangeAnalysisInternal::countNrOfUpperBounds(e)
|
||||
or
|
||||
not exists(SimpleRangeAnalysisInternal::countNrOfUpperBounds(e)) and actualNrOfUpperBounds = -1
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user