From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Sat, 7 May 2022 22:12:41 -0400 Subject: [PATCH 02/31] Wrap std::min/max calls in parens, for Windows warnings --- llvm/include/llvm/ADT/DenseMap.h | 4 ++-- llvm/include/llvm/ADT/SmallVector.h | 12 ++++++------ llvm/include/llvm/Support/ConvertUTF.h | 2 +- llvm/include/llvm/Support/MathExtras.h | 18 +++++++++--------- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h index 3ef6a7cd1b4b587e61fcb9475d9f3516018bf2ee..108193f04486425f3b7f039cd9d2004be6facafb 100644 --- a/llvm/include/llvm/ADT/DenseMap.h +++ b/llvm/include/llvm/ADT/DenseMap.h @@ -416,7 +416,7 @@ protected: return 0; // +1 is required because of the strict equality. // For example if NumEntries is 48, we need to return 401. - return NextPowerOf2(NumEntries * 4 / 3 + 1); + return static_cast(NextPowerOf2(NumEntries * 4 / 3 + 1)); } void moveFromOldBuckets(BucketT *OldBucketsBegin, BucketT *OldBucketsEnd) { @@ -852,7 +852,7 @@ public: // Reduce the number of buckets. unsigned NewNumBuckets = 0; if (OldNumEntries) - NewNumBuckets = std::max(64, 1 << (Log2_32_Ceil(OldNumEntries) + 1)); + NewNumBuckets = (std::max)(64, 1 << (Log2_32_Ceil(OldNumEntries) + 1)); if (NewNumBuckets == NumBuckets) { this->BaseT::initEmpty(); return; diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h index 4559864ed231206b098936dae4fc378bfa986371..84f4d0931a30f4be29549354c85cb4c0489e14c9 100644 --- a/llvm/include/llvm/ADT/SmallVector.h +++ b/llvm/include/llvm/ADT/SmallVector.h @@ -55,12 +55,12 @@ protected: /// The maximum value of the Size_T used. static constexpr size_t SizeTypeMax() { - return std::numeric_limits::max(); + return (std::numeric_limits::max)(); } SmallVectorBase() = delete; SmallVectorBase(void *FirstEl, size_t TotalCapacity) - : BeginX(FirstEl), Capacity(TotalCapacity) {} + : BeginX(FirstEl), Capacity(static_cast(TotalCapacity)) {} /// This is a helper for \a grow() that's out of line to reduce code /// duplication. This function will report a fatal error if it can't grow at @@ -99,7 +99,7 @@ protected: /// This does not construct or destroy any elements in the vector. void set_size(size_t N) { assert(N <= capacity()); - Size = N; + Size = static_cast(N); } }; @@ -279,7 +279,7 @@ public: size_type size_in_bytes() const { return size() * sizeof(T); } size_type max_size() const { - return std::min(this->SizeTypeMax(), size_type(-1) / sizeof(T)); + return (std::min)(this->SizeTypeMax(), size_type(-1) / sizeof(T)); } size_t capacity_in_bytes() const { return capacity() * sizeof(T); } @@ -467,7 +467,7 @@ void SmallVectorTemplateBase::takeAllocationForGrow( free(this->begin()); this->BeginX = NewElts; - this->Capacity = NewCapacity; + this->Capacity = static_cast(NewCapacity); } /// SmallVectorTemplateBase - This is where we put @@ -712,7 +712,7 @@ public: } // Assign over existing elements. - std::fill_n(this->begin(), std::min(NumElts, this->size()), Elt); + std::fill_n(this->begin(), (std::min)(NumElts, this->size()), Elt); if (NumElts > this->size()) std::uninitialized_fill_n(this->end(), NumElts - this->size(), Elt); else if (NumElts < this->size()) diff --git a/llvm/include/llvm/Support/ConvertUTF.h b/llvm/include/llvm/Support/ConvertUTF.h index 5c0e3009c25446a34882fb98329b1d955231bb39..72321022beb373945f7935ed72944fd68eb7d02f 100644 --- a/llvm/include/llvm/Support/ConvertUTF.h +++ b/llvm/include/llvm/Support/ConvertUTF.h @@ -127,7 +127,7 @@ namespace llvm { typedef unsigned int UTF32; /* at least 32 bits */ typedef unsigned short UTF16; /* at least 16 bits */ typedef unsigned char UTF8; /* typically 8 bits */ -typedef unsigned char Boolean; /* 0 or 1 */ +typedef bool Boolean; /* 0 or 1 */ /* Some fundamental constants */ #define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h index dc095941fdc8a9f2b3b822e6e014f0640676c0d3..0bd572d07fcbf2ff56998dbf366215068b62f527 100644 --- a/llvm/include/llvm/Support/MathExtras.h +++ b/llvm/include/llvm/Support/MathExtras.h @@ -311,26 +311,26 @@ template <> constexpr inline size_t CTLog2<1>() { return 0; } /// (32 bit edition.) /// Ex. Log2_32(32) == 5, Log2_32(1) == 0, Log2_32(0) == -1, Log2_32(6) == 2 inline unsigned Log2_32(uint32_t Value) { - return 31 - llvm::countl_zero(Value); + return static_cast(31 - llvm::countl_zero(Value)); } /// Return the floor log base 2 of the specified value, -1 if the value is zero. /// (64 bit edition.) inline unsigned Log2_64(uint64_t Value) { - return 63 - llvm::countl_zero(Value); + return static_cast(63 - llvm::countl_zero(Value)); } /// Return the ceil log base 2 of the specified value, 32 if the value is zero. /// (32 bit edition). /// Ex. Log2_32_Ceil(32) == 5, Log2_32_Ceil(1) == 0, Log2_32_Ceil(6) == 3 inline unsigned Log2_32_Ceil(uint32_t Value) { - return 32 - llvm::countl_zero(Value - 1); + return static_cast(32 - llvm::countl_zero(Value - 1)); } /// Return the ceil log base 2 of the specified value, 64 if the value is zero. /// (64 bit edition.) inline unsigned Log2_64_Ceil(uint64_t Value) { - return 64 - llvm::countl_zero(Value - 1); + return static_cast(64 - llvm::countl_zero(Value - 1)); } /// A and B are either alignments or offsets. Return the minimum alignment that @@ -479,7 +479,7 @@ SaturatingAdd(T X, T Y, bool *ResultOverflowed = nullptr) { T Z = X + Y; Overflowed = (Z < X || Z < Y); if (Overflowed) - return std::numeric_limits::max(); + return (std::numeric_limits::max)(); else return Z; } @@ -492,7 +492,7 @@ std::enable_if_t, T> SaturatingAdd(T X, T Y, T Z, bool Overflowed = false; T XY = SaturatingAdd(X, Y, &Overflowed); if (Overflowed) - return SaturatingAdd(std::numeric_limits::max(), T(1), Args...); + return SaturatingAdd((std::numeric_limits::max)(), T(1), Args...); return SaturatingAdd(XY, Z, Args...); } @@ -516,7 +516,7 @@ SaturatingMultiply(T X, T Y, bool *ResultOverflowed = nullptr) { // Special case: if X or Y is 0, Log2_64 gives -1, and Log2Z // will necessarily be less than Log2Max as desired. int Log2Z = Log2_64(X) + Log2_64(Y); - const T Max = std::numeric_limits::max(); + const T Max = (std::numeric_limits::max)(); int Log2Max = Log2_64(Max); if (Log2Z < Log2Max) { return X * Y; @@ -636,9 +636,9 @@ std::enable_if_t, T> MulOverflow(T X, T Y, T &Result) { // Check how the max allowed absolute value (2^n for negative, 2^(n-1) for // positive) divided by an argument compares to the other. if (IsNegative) - return UX > (static_cast(std::numeric_limits::max()) + U(1)) / UY; + return UX > (static_cast((std::numeric_limits::max)()) + U(1)) / UY; else - return UX > (static_cast(std::numeric_limits::max())) / UY; + return UX > (static_cast((std::numeric_limits::max)())) / UY; } } // End llvm namespace