blob: a67e32665027a9f5b46b0446c11985cb65621455 [file] [log] [blame]
From 5fccde024bea117d90d215390f09c7d779195ea5 Mon Sep 17 00:00:00 2001
From: PJ Reiniger <pj.reiniger@gmail.com>
Date: Sat, 7 May 2022 22:12:41 -0400
Subject: [PATCH 03/28] 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 | 22 +++++++++++-----------
llvm/lib/Support/SmallVector.cpp | 2 +-
5 files changed, 21 insertions(+), 21 deletions(-)
diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h
index 7673b66ca..975c3b97e 100644
--- a/llvm/include/llvm/ADT/DenseMap.h
+++ b/llvm/include/llvm/ADT/DenseMap.h
@@ -390,7 +390,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<unsigned>(NextPowerOf2(NumEntries * 4 / 3 + 1));
}
void moveFromOldBuckets(BucketT *OldBucketsBegin, BucketT *OldBucketsEnd) {
@@ -826,7 +826,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 a4a790323..8686f7bb5 100644
--- a/llvm/include/llvm/ADT/SmallVector.h
+++ b/llvm/include/llvm/ADT/SmallVector.h
@@ -49,12 +49,12 @@ protected:
/// The maximum value of the Size_T used.
static constexpr size_t SizeTypeMax() {
- return std::numeric_limits<Size_T>::max();
+ return (std::numeric_limits<Size_T>::max)();
}
SmallVectorBase() = delete;
SmallVectorBase(void *FirstEl, size_t TotalCapacity)
- : BeginX(FirstEl), Capacity(TotalCapacity) {}
+ : BeginX(FirstEl), Capacity(static_cast<unsigned>(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
@@ -79,7 +79,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<unsigned>(N);
}
};
@@ -259,7 +259,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); }
@@ -444,7 +444,7 @@ void SmallVectorTemplateBase<T, TriviallyCopyable>::takeAllocationForGrow(
free(this->begin());
this->BeginX = NewElts;
- this->Capacity = NewCapacity;
+ this->Capacity = static_cast<unsigned>(NewCapacity);
}
/// SmallVectorTemplateBase<TriviallyCopyable = true> - This is where we put
@@ -693,7 +693,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 7f1527f51..b085c8a17 100644
--- a/llvm/include/llvm/Support/ConvertUTF.h
+++ b/llvm/include/llvm/Support/ConvertUTF.h
@@ -112,7 +112,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 753b1998c..db9fbc148 100644
--- a/llvm/include/llvm/Support/MathExtras.h
+++ b/llvm/include/llvm/Support/MathExtras.h
@@ -97,7 +97,7 @@ template <typename T, std::size_t SizeOfT> struct TrailingZerosCounter {
// Bisection method.
unsigned ZeroBits = 0;
T Shift = std::numeric_limits<T>::digits >> 1;
- T Mask = std::numeric_limits<T>::max() >> Shift;
+ T Mask = (std::numeric_limits<T>::max)() >> Shift;
while (Shift) {
if ((Val & Mask) == 0) {
Val >>= Shift;
@@ -238,7 +238,7 @@ unsigned countLeadingZeros(T Val, ZeroBehavior ZB = ZB_Width) {
/// valid arguments.
template <typename T> T findFirstSet(T Val, ZeroBehavior ZB = ZB_Max) {
if (ZB == ZB_Max && Val == 0)
- return std::numeric_limits<T>::max();
+ return (std::numeric_limits<T>::max)();
return countTrailingZeros(Val, ZB_Undefined);
}
@@ -279,7 +279,7 @@ template <typename T> T maskLeadingZeros(unsigned N) {
/// valid arguments.
template <typename T> T findLastSet(T Val, ZeroBehavior ZB = ZB_Max) {
if (ZB == ZB_Max && Val == 0)
- return std::numeric_limits<T>::max();
+ return (std::numeric_limits<T>::max)();
// Use ^ instead of - because both gcc and llvm can remove the associated ^
// in the __builtin_clz intrinsic on x86.
@@ -594,26 +594,26 @@ inline double Log2(double Value) {
/// (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 - countLeadingZeros(Value);
+ return static_cast<unsigned>(31 - countLeadingZeros(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 - countLeadingZeros(Value);
+ return static_cast<unsigned>(63 - countLeadingZeros(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 - countLeadingZeros(Value - 1);
+ return static_cast<unsigned>(32 - countLeadingZeros(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 - countLeadingZeros(Value - 1);
+ return static_cast<unsigned>(64 - countLeadingZeros(Value - 1));
}
/// Return the greatest common divisor of the values using Euclid's algorithm.
@@ -807,7 +807,7 @@ SaturatingAdd(T X, T Y, bool *ResultOverflowed = nullptr) {
T Z = X + Y;
Overflowed = (Z < X || Z < Y);
if (Overflowed)
- return std::numeric_limits<T>::max();
+ return (std::numeric_limits<T>::max)();
else
return Z;
}
@@ -832,7 +832,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<T>::max();
+ const T Max = (std::numeric_limits<T>::max)();
int Log2Max = Log2_64(Max);
if (Log2Z < Log2Max) {
return X * Y;
@@ -952,9 +952,9 @@ std::enable_if_t<std::is_signed<T>::value, 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<U>(std::numeric_limits<T>::max()) + U(1)) / UY;
+ return UX > (static_cast<U>((std::numeric_limits<T>::max)()) + U(1)) / UY;
else
- return UX > (static_cast<U>(std::numeric_limits<T>::max())) / UY;
+ return UX > (static_cast<U>((std::numeric_limits<T>::max)())) / UY;
}
} // End llvm namespace
diff --git a/llvm/lib/Support/SmallVector.cpp b/llvm/lib/Support/SmallVector.cpp
index 8bad715e4..a2b4899e1 100644
--- a/llvm/lib/Support/SmallVector.cpp
+++ b/llvm/lib/Support/SmallVector.cpp
@@ -104,7 +104,7 @@ static size_t getNewCapacity(size_t MinSize, size_t TSize, size_t OldCapacity) {
// In theory 2*capacity can overflow if the capacity is 64 bit, but the
// original capacity would never be large enough for this to be a problem.
size_t NewCapacity = 2 * OldCapacity + 1; // Always grow.
- return std::min(std::max(NewCapacity, MinSize), MaxSize);
+ return (std::min)((std::max)(NewCapacity, MinSize), MaxSize);
}
// Note: Moving this function into the header may cause performance regression.