https://github.com/NagyDonat created https://github.com/llvm/llvm-project/pull/126941
Two small stylistic improvements in code that I wrote ~a year ago: 1. fix a typo in a comment; and 2. simplify the code of `tryDividePair` by swapping the true and the false branches. From a0b6f3aff5e639d4388def07cc88d8c6f9033508 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Don=C3=A1t=20Nagy?= <donat.n...@ericsson.com> Date: Wed, 12 Feb 2025 17:17:11 +0100 Subject: [PATCH] [analyzer][NFC] Trivial cleanup in ArrayBoundChecker Two small stylistic improvements in code that I wrote ~a year ago: 1. fix a typo in a comment; and 2. simplify the code of `tryDividePair` by swapping the true and the false branches. --- .../Checkers/ArrayBoundChecker.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp index 109faacf1726a..f56e9192d1d66 100644 --- a/clang/lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp @@ -323,7 +323,7 @@ compareValueToThreshold(ProgramStateRef State, NonLoc Value, NonLoc Threshold, // we want to ensure that assumptions coming from this precondition and // assumptions coming from regular C/C++ operator calls are represented by // constraints on the same symbolic expression. A solution that would - // evaluate these "mathematical" compariosns through a separate pathway would + // evaluate these "mathematical" comparisons through a separate pathway would // be a step backwards in this sense. const BinaryOperatorKind OpKind = CheckEquality ? BO_EQ : BO_LT; @@ -394,14 +394,13 @@ static bool tryDividePair(std::optional<int64_t> &Val1, return false; const bool Val1HasRemainder = Val1 && *Val1 % Divisor; const bool Val2HasRemainder = Val2 && *Val2 % Divisor; - if (!Val1HasRemainder && !Val2HasRemainder) { - if (Val1) - *Val1 /= Divisor; - if (Val2) - *Val2 /= Divisor; - return true; - } - return false; + if (Val1HasRemainder || Val2HasRemainder) + return false; + if (Val1) + *Val1 /= Divisor; + if (Val2) + *Val2 /= Divisor; + return true; } static Messages getExceedsMsgs(ASTContext &ACtx, const SubRegion *Region, _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits