blob: a67e32665027a9f5b46b0446c11985cb65621455 [file] [log] [blame]
James Kuszmaulcf324122023-01-14 14:07:17 -08001From 5fccde024bea117d90d215390f09c7d779195ea5 Mon Sep 17 00:00:00 2001
2From: PJ Reiniger <pj.reiniger@gmail.com>
3Date: Sat, 7 May 2022 22:12:41 -0400
4Subject: [PATCH 03/28] Wrap std::min/max calls in parens, for Windows warnings
5
6---
7 llvm/include/llvm/ADT/DenseMap.h | 4 ++--
8 llvm/include/llvm/ADT/SmallVector.h | 12 ++++++------
9 llvm/include/llvm/Support/ConvertUTF.h | 2 +-
10 llvm/include/llvm/Support/MathExtras.h | 22 +++++++++++-----------
11 llvm/lib/Support/SmallVector.cpp | 2 +-
12 5 files changed, 21 insertions(+), 21 deletions(-)
13
14diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h
15index 7673b66ca..975c3b97e 100644
16--- a/llvm/include/llvm/ADT/DenseMap.h
17+++ b/llvm/include/llvm/ADT/DenseMap.h
18@@ -390,7 +390,7 @@ protected:
19 return 0;
20 // +1 is required because of the strict equality.
21 // For example if NumEntries is 48, we need to return 401.
22- return NextPowerOf2(NumEntries * 4 / 3 + 1);
23+ return static_cast<unsigned>(NextPowerOf2(NumEntries * 4 / 3 + 1));
24 }
25
26 void moveFromOldBuckets(BucketT *OldBucketsBegin, BucketT *OldBucketsEnd) {
27@@ -826,7 +826,7 @@ public:
28 // Reduce the number of buckets.
29 unsigned NewNumBuckets = 0;
30 if (OldNumEntries)
31- NewNumBuckets = std::max(64, 1 << (Log2_32_Ceil(OldNumEntries) + 1));
32+ NewNumBuckets = (std::max)(64, 1 << (Log2_32_Ceil(OldNumEntries) + 1));
33 if (NewNumBuckets == NumBuckets) {
34 this->BaseT::initEmpty();
35 return;
36diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h
37index a4a790323..8686f7bb5 100644
38--- a/llvm/include/llvm/ADT/SmallVector.h
39+++ b/llvm/include/llvm/ADT/SmallVector.h
40@@ -49,12 +49,12 @@ protected:
41
42 /// The maximum value of the Size_T used.
43 static constexpr size_t SizeTypeMax() {
44- return std::numeric_limits<Size_T>::max();
45+ return (std::numeric_limits<Size_T>::max)();
46 }
47
48 SmallVectorBase() = delete;
49 SmallVectorBase(void *FirstEl, size_t TotalCapacity)
50- : BeginX(FirstEl), Capacity(TotalCapacity) {}
51+ : BeginX(FirstEl), Capacity(static_cast<unsigned>(TotalCapacity)) {}
52
53 /// This is a helper for \a grow() that's out of line to reduce code
54 /// duplication. This function will report a fatal error if it can't grow at
55@@ -79,7 +79,7 @@ protected:
56 /// This does not construct or destroy any elements in the vector.
57 void set_size(size_t N) {
58 assert(N <= capacity());
59- Size = N;
60+ Size = static_cast<unsigned>(N);
61 }
62 };
63
64@@ -259,7 +259,7 @@ public:
65
66 size_type size_in_bytes() const { return size() * sizeof(T); }
67 size_type max_size() const {
68- return std::min(this->SizeTypeMax(), size_type(-1) / sizeof(T));
69+ return (std::min)(this->SizeTypeMax(), size_type(-1) / sizeof(T));
70 }
71
72 size_t capacity_in_bytes() const { return capacity() * sizeof(T); }
73@@ -444,7 +444,7 @@ void SmallVectorTemplateBase<T, TriviallyCopyable>::takeAllocationForGrow(
74 free(this->begin());
75
76 this->BeginX = NewElts;
77- this->Capacity = NewCapacity;
78+ this->Capacity = static_cast<unsigned>(NewCapacity);
79 }
80
81 /// SmallVectorTemplateBase<TriviallyCopyable = true> - This is where we put
82@@ -693,7 +693,7 @@ public:
83 }
84
85 // Assign over existing elements.
86- std::fill_n(this->begin(), std::min(NumElts, this->size()), Elt);
87+ std::fill_n(this->begin(), (std::min)(NumElts, this->size()), Elt);
88 if (NumElts > this->size())
89 std::uninitialized_fill_n(this->end(), NumElts - this->size(), Elt);
90 else if (NumElts < this->size())
91diff --git a/llvm/include/llvm/Support/ConvertUTF.h b/llvm/include/llvm/Support/ConvertUTF.h
92index 7f1527f51..b085c8a17 100644
93--- a/llvm/include/llvm/Support/ConvertUTF.h
94+++ b/llvm/include/llvm/Support/ConvertUTF.h
95@@ -112,7 +112,7 @@ namespace llvm {
96 typedef unsigned int UTF32; /* at least 32 bits */
97 typedef unsigned short UTF16; /* at least 16 bits */
98 typedef unsigned char UTF8; /* typically 8 bits */
99-typedef unsigned char Boolean; /* 0 or 1 */
100+typedef bool Boolean; /* 0 or 1 */
101
102 /* Some fundamental constants */
103 #define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD
104diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h
105index 753b1998c..db9fbc148 100644
106--- a/llvm/include/llvm/Support/MathExtras.h
107+++ b/llvm/include/llvm/Support/MathExtras.h
108@@ -97,7 +97,7 @@ template <typename T, std::size_t SizeOfT> struct TrailingZerosCounter {
109 // Bisection method.
110 unsigned ZeroBits = 0;
111 T Shift = std::numeric_limits<T>::digits >> 1;
112- T Mask = std::numeric_limits<T>::max() >> Shift;
113+ T Mask = (std::numeric_limits<T>::max)() >> Shift;
114 while (Shift) {
115 if ((Val & Mask) == 0) {
116 Val >>= Shift;
117@@ -238,7 +238,7 @@ unsigned countLeadingZeros(T Val, ZeroBehavior ZB = ZB_Width) {
118 /// valid arguments.
119 template <typename T> T findFirstSet(T Val, ZeroBehavior ZB = ZB_Max) {
120 if (ZB == ZB_Max && Val == 0)
121- return std::numeric_limits<T>::max();
122+ return (std::numeric_limits<T>::max)();
123
124 return countTrailingZeros(Val, ZB_Undefined);
125 }
126@@ -279,7 +279,7 @@ template <typename T> T maskLeadingZeros(unsigned N) {
127 /// valid arguments.
128 template <typename T> T findLastSet(T Val, ZeroBehavior ZB = ZB_Max) {
129 if (ZB == ZB_Max && Val == 0)
130- return std::numeric_limits<T>::max();
131+ return (std::numeric_limits<T>::max)();
132
133 // Use ^ instead of - because both gcc and llvm can remove the associated ^
134 // in the __builtin_clz intrinsic on x86.
135@@ -594,26 +594,26 @@ inline double Log2(double Value) {
136 /// (32 bit edition.)
137 /// Ex. Log2_32(32) == 5, Log2_32(1) == 0, Log2_32(0) == -1, Log2_32(6) == 2
138 inline unsigned Log2_32(uint32_t Value) {
139- return 31 - countLeadingZeros(Value);
140+ return static_cast<unsigned>(31 - countLeadingZeros(Value));
141 }
142
143 /// Return the floor log base 2 of the specified value, -1 if the value is zero.
144 /// (64 bit edition.)
145 inline unsigned Log2_64(uint64_t Value) {
146- return 63 - countLeadingZeros(Value);
147+ return static_cast<unsigned>(63 - countLeadingZeros(Value));
148 }
149
150 /// Return the ceil log base 2 of the specified value, 32 if the value is zero.
151 /// (32 bit edition).
152 /// Ex. Log2_32_Ceil(32) == 5, Log2_32_Ceil(1) == 0, Log2_32_Ceil(6) == 3
153 inline unsigned Log2_32_Ceil(uint32_t Value) {
154- return 32 - countLeadingZeros(Value - 1);
155+ return static_cast<unsigned>(32 - countLeadingZeros(Value - 1));
156 }
157
158 /// Return the ceil log base 2 of the specified value, 64 if the value is zero.
159 /// (64 bit edition.)
160 inline unsigned Log2_64_Ceil(uint64_t Value) {
161- return 64 - countLeadingZeros(Value - 1);
162+ return static_cast<unsigned>(64 - countLeadingZeros(Value - 1));
163 }
164
165 /// Return the greatest common divisor of the values using Euclid's algorithm.
166@@ -807,7 +807,7 @@ SaturatingAdd(T X, T Y, bool *ResultOverflowed = nullptr) {
167 T Z = X + Y;
168 Overflowed = (Z < X || Z < Y);
169 if (Overflowed)
170- return std::numeric_limits<T>::max();
171+ return (std::numeric_limits<T>::max)();
172 else
173 return Z;
174 }
175@@ -832,7 +832,7 @@ SaturatingMultiply(T X, T Y, bool *ResultOverflowed = nullptr) {
176 // Special case: if X or Y is 0, Log2_64 gives -1, and Log2Z
177 // will necessarily be less than Log2Max as desired.
178 int Log2Z = Log2_64(X) + Log2_64(Y);
179- const T Max = std::numeric_limits<T>::max();
180+ const T Max = (std::numeric_limits<T>::max)();
181 int Log2Max = Log2_64(Max);
182 if (Log2Z < Log2Max) {
183 return X * Y;
184@@ -952,9 +952,9 @@ std::enable_if_t<std::is_signed<T>::value, T> MulOverflow(T X, T Y, T &Result) {
185 // Check how the max allowed absolute value (2^n for negative, 2^(n-1) for
186 // positive) divided by an argument compares to the other.
187 if (IsNegative)
188- return UX > (static_cast<U>(std::numeric_limits<T>::max()) + U(1)) / UY;
189+ return UX > (static_cast<U>((std::numeric_limits<T>::max)()) + U(1)) / UY;
190 else
191- return UX > (static_cast<U>(std::numeric_limits<T>::max())) / UY;
192+ return UX > (static_cast<U>((std::numeric_limits<T>::max)())) / UY;
193 }
194
195 } // End llvm namespace
196diff --git a/llvm/lib/Support/SmallVector.cpp b/llvm/lib/Support/SmallVector.cpp
197index 8bad715e4..a2b4899e1 100644
198--- a/llvm/lib/Support/SmallVector.cpp
199+++ b/llvm/lib/Support/SmallVector.cpp
200@@ -104,7 +104,7 @@ static size_t getNewCapacity(size_t MinSize, size_t TSize, size_t OldCapacity) {
201 // In theory 2*capacity can overflow if the capacity is 64 bit, but the
202 // original capacity would never be large enough for this to be a problem.
203 size_t NewCapacity = 2 * OldCapacity + 1; // Always grow.
204- return std::min(std::max(NewCapacity, MinSize), MaxSize);
205+ return (std::min)((std::max)(NewCapacity, MinSize), MaxSize);
206 }
207
208 // Note: Moving this function into the header may cause performance regression.