From: Artem Dergachev Date: Mon, 24 Oct 2016 18:49:04 +0000 (+0000) Subject: [analyzer] Use unsigned integers to rely on well-defined overflow semantics. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1048d282e7617e6bac1a5c8a55554edaf4a670b6;p=clang [analyzer] Use unsigned integers to rely on well-defined overflow semantics. Found by the UBSan buildbot. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285000 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp b/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp index 8e77be5427..2aa222ad24 100644 --- a/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp @@ -83,7 +83,7 @@ class StdLibraryFunctionsChecker : public Checker { /// a non-negative integer, which less than 5 and not equal to 2. For /// `ComparesToArgument', holds information about how exactly to compare to /// the argument. - typedef std::vector> IntRangeVectorTy; + typedef std::vector> IntRangeVectorTy; /// A reference to an argument or return value by its number. /// ArgNo in CallExpr and CallEvent is defined as Unsigned, but @@ -274,7 +274,7 @@ StdLibraryFunctionsChecker::ValueRange::applyAsWithinRange( const llvm::APSInt &MinusInf = BVF.getMinValue(T); const llvm::APSInt &PlusInf = BVF.getMaxValue(T); - const llvm::APSInt &Left = BVF.getValue(R[0].first - 1, T); + const llvm::APSInt &Left = BVF.getValue(R[0].first - 1ULL, T); if (Left != PlusInf) { assert(MinusInf <= Left); State = CM.assumeWithinInclusiveRange(State, *N, MinusInf, Left, false); @@ -282,7 +282,7 @@ StdLibraryFunctionsChecker::ValueRange::applyAsWithinRange( return nullptr; } - const llvm::APSInt &Right = BVF.getValue(R[E - 1].second + 1, T); + const llvm::APSInt &Right = BVF.getValue(R[E - 1].second + 1ULL, T); if (Right != MinusInf) { assert(Right <= PlusInf); State = CM.assumeWithinInclusiveRange(State, *N, Right, PlusInf, false); @@ -291,8 +291,8 @@ StdLibraryFunctionsChecker::ValueRange::applyAsWithinRange( } for (size_t I = 1; I != E; ++I) { - const llvm::APSInt &Min = BVF.getValue(R[I - 1].second + 1, T); - const llvm::APSInt &Max = BVF.getValue(R[I].first - 1, T); + const llvm::APSInt &Min = BVF.getValue(R[I - 1].second + 1ULL, T); + const llvm::APSInt &Max = BVF.getValue(R[I].first - 1ULL, T); assert(Min <= Max); State = CM.assumeWithinInclusiveRange(State, *N, Min, Max, false); if (!State)