Skip to content

Commit 594c40a

Browse files
authored
Merge pull request #10355 from MathiasVP/fix-unequalIntegralSsa-standard-order
C++: Avoid bad standard order in range analysis
2 parents b3653cc + f119b50 commit 594c40a

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

cpp/ql/lib/experimental/semmle/code/cpp/semantic/analysis/RangeAnalysis.qll

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,12 +542,32 @@ private predicate unequalIntegralSsa(
542542
) {
543543
exists(SemExpr e, int d1, int d2 |
544544
unequalFlowStepIntegralSsa(v, pos, e, d1, reason) and
545-
bounded(e, b, d2, true, _, _, _) and
546-
bounded(e, b, d2, false, _, _, _) and
545+
boundedUpper(e, b, d1) and
546+
boundedLower(e, b, d2) and
547547
delta = d2 + d1
548548
)
549549
}
550550

551+
/**
552+
* Holds if `b + delta` is an upper bound for `e`.
553+
*
554+
* This predicate only exists to prevent a bad standard order in `unequalIntegralSsa`.
555+
*/
556+
pragma[nomagic]
557+
private predicate boundedUpper(SemExpr e, SemBound b, int delta) {
558+
bounded(e, b, delta, true, _, _, _)
559+
}
560+
561+
/**
562+
* Holds if `b + delta` is a lower bound for `e`.
563+
*
564+
* This predicate only exists to prevent a bad standard order in `unequalIntegralSsa`.
565+
*/
566+
pragma[nomagic]
567+
private predicate boundedLower(SemExpr e, SemBound b, int delta) {
568+
bounded(e, b, delta, false, _, _, _)
569+
}
570+
551571
/** Weakens a delta to lie in the range `[-1..1]`. */
552572
bindingset[delta, upper]
553573
private int weakenDelta(boolean upper, int delta) {

0 commit comments

Comments
 (0)