From d1ea1af9452f29ec32ad2d48d0206de683ad7559 Mon Sep 17 00:00:00 2001 From: Simon Friis Vindum Date: Fri, 24 Oct 2025 16:16:57 +0200 Subject: [PATCH] C++: Make small trivial tweaks --- .../code/cpp/rangeanalysis/RangeAnalysisUtils.qll | 8 ++++---- .../code/cpp/rangeanalysis/SimpleRangeAnalysis.qll | 14 +++++--------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/cpp/ql/lib/semmle/code/cpp/rangeanalysis/RangeAnalysisUtils.qll b/cpp/ql/lib/semmle/code/cpp/rangeanalysis/RangeAnalysisUtils.qll index 58c82445331..2423a3a71a0 100644 --- a/cpp/ql/lib/semmle/code/cpp/rangeanalysis/RangeAnalysisUtils.qll +++ b/cpp/ql/lib/semmle/code/cpp/rangeanalysis/RangeAnalysisUtils.qll @@ -118,10 +118,10 @@ predicate relOpWithSwap( * * This allows for the relation to be either as written, or with its * arguments reversed; for example, if `rel` is `x < 5` then - * `relOpWithSwapAndNegate(rel, x, 5, Lesser(), Strict(), true)`, - * `relOpWithSwapAndNegate(rel, 5, x, Greater(), Strict(), true)`, - * `relOpWithSwapAndNegate(rel, x, 5, Greater(), Nonstrict(), false)` and - * `relOpWithSwapAndNegate(rel, 5, x, Lesser(), Nonstrict(), false)` hold. + * - `relOpWithSwapAndNegate(rel, x, 5, Lesser(), Strict(), true)`, + * - `relOpWithSwapAndNegate(rel, 5, x, Greater(), Strict(), true)`, + * - `relOpWithSwapAndNegate(rel, x, 5, Greater(), Nonstrict(), false)` and + * - `relOpWithSwapAndNegate(rel, 5, x, Lesser(), Nonstrict(), false)` hold. */ predicate relOpWithSwapAndNegate( RelationalOperation rel, Expr a, Expr b, RelationDirection dir, RelationStrictness strict, diff --git a/cpp/ql/lib/semmle/code/cpp/rangeanalysis/SimpleRangeAnalysis.qll b/cpp/ql/lib/semmle/code/cpp/rangeanalysis/SimpleRangeAnalysis.qll index 942b8155139..fcb99487d2a 100644 --- a/cpp/ql/lib/semmle/code/cpp/rangeanalysis/SimpleRangeAnalysis.qll +++ b/cpp/ql/lib/semmle/code/cpp/rangeanalysis/SimpleRangeAnalysis.qll @@ -1213,7 +1213,7 @@ private float getLowerBoundsImpl(Expr expr) { // equal to `min(-y + 1,y - 1)`. exists(float childLB | childLB = getFullyConvertedLowerBounds(remExpr.getAnOperand()) and - not childLB >= 0 + childLB < 0 | result = getFullyConvertedLowerBounds(remExpr.getRightOperand()) - 1 or @@ -1425,8 +1425,7 @@ private float getUpperBoundsImpl(Expr expr) { // adding `-rhsLB` to the set of upper bounds. exists(float rhsLB | rhsLB = getFullyConvertedLowerBounds(remExpr.getRightOperand()) and - not rhsLB >= 0 - | + rhsLB < 0 and result = -rhsLB + 1 ) ) @@ -1571,8 +1570,7 @@ private float getPhiLowerBounds(StackVariable v, RangeSsaDefinition phi) { exists(VariableAccess access, Expr guard, boolean branch, float defLB, float guardLB | phi.isGuardPhi(v, access, guard, branch) and lowerBoundFromGuard(guard, access, guardLB, branch) and - defLB = getFullyConvertedLowerBounds(access) - | + defLB = getFullyConvertedLowerBounds(access) and // Compute the maximum of `guardLB` and `defLB`. if guardLB > defLB then result = guardLB else result = defLB ) @@ -1596,8 +1594,7 @@ private float getPhiUpperBounds(StackVariable v, RangeSsaDefinition phi) { exists(VariableAccess access, Expr guard, boolean branch, float defUB, float guardUB | phi.isGuardPhi(v, access, guard, branch) and upperBoundFromGuard(guard, access, guardUB, branch) and - defUB = getFullyConvertedUpperBounds(access) - | + defUB = getFullyConvertedUpperBounds(access) and // Compute the minimum of `guardUB` and `defUB`. if guardUB < defUB then result = guardUB else result = defUB ) @@ -1761,8 +1758,7 @@ private predicate upperBoundFromGuard(Expr guard, VariableAccess v, float ub, bo } /** - * This predicate simplifies the results returned by - * `linearBoundFromGuard`. + * This predicate simplifies the results returned by `linearBoundFromGuard`. */ private predicate boundFromGuard( Expr guard, VariableAccess v, float boundValue, boolean isLowerBound,