Skip to content

Commit 72d0470

Browse files
committed
C++: Add debug predicates for the simple range analysis
1 parent ea43f16 commit 72d0470

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

cpp/ql/lib/semmle/code/cpp/rangeanalysis/SimpleRangeAnalysis.qll

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,3 +1860,34 @@ module SimpleRangeAnalysisInternal {
18601860
defMightOverflowNegatively(def, v) and result = varMaxVal(v)
18611861
}
18621862
}
1863+
1864+
/** Provides predicates for debugging the simple range analysis library. */
1865+
private module Debug {
1866+
Locatable getRelevantLocatable() {
1867+
exists(string filepath, int startline, int startcolumn, int endline, int endcolumn |
1868+
result.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and
1869+
filepath.matches("%/test.c") and
1870+
startline = [464 .. 472]
1871+
)
1872+
}
1873+
1874+
float debugGetFullyConvertedLowerBounds(Expr expr) {
1875+
expr = getRelevantLocatable() and
1876+
result = getFullyConvertedLowerBounds(expr)
1877+
}
1878+
1879+
float debugGetLowerBoundsImpl(Expr e, string kl) {
1880+
e = getRelevantLocatable() and
1881+
result = getLowerBoundsImpl(e) and
1882+
kl = e.getPrimaryQlClasses()
1883+
}
1884+
1885+
/**
1886+
* Counts the number of lower bounds for a given expression. This predicate is
1887+
* useful for identifying performance issues in the range analysis.
1888+
*/
1889+
predicate nrOfLowerBounds(Expr e, int n) {
1890+
e = getRelevantLocatable() and
1891+
n = strictcount(float lb | lb = getLowerBoundsImpl(e) | lb)
1892+
}
1893+
}

0 commit comments

Comments
 (0)