blob: fe5c48ef4973432d6537784604d47ed49e65d2f4 [file] [log] [blame]
James Kuszmaulb13e13f2023-11-22 20:44:04 -08001From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
James Kuszmaulcf324122023-01-14 14:07:17 -08002From: PJ Reiniger <pj.reiniger@gmail.com>
3Date: Sat, 7 May 2022 22:12:41 -0400
James Kuszmaulb13e13f2023-11-22 20:44:04 -08004Subject: [PATCH 02/31] Wrap std::min/max calls in parens, for Windows warnings
James Kuszmaulcf324122023-01-14 14:07:17 -08005
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 +-
James Kuszmaulb13e13f2023-11-22 20:44:04 -080010 llvm/include/llvm/Support/MathExtras.h | 18 +++++++++---------
11 4 files changed, 18 insertions(+), 18 deletions(-)
James Kuszmaulcf324122023-01-14 14:07:17 -080012
13diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h
James Kuszmaulb13e13f2023-11-22 20:44:04 -080014index 3ef6a7cd1b4b587e61fcb9475d9f3516018bf2ee..108193f04486425f3b7f039cd9d2004be6facafb 100644
James Kuszmaulcf324122023-01-14 14:07:17 -080015--- a/llvm/include/llvm/ADT/DenseMap.h
16+++ b/llvm/include/llvm/ADT/DenseMap.h
James Kuszmaulb13e13f2023-11-22 20:44:04 -080017@@ -416,7 +416,7 @@ protected:
James Kuszmaulcf324122023-01-14 14:07:17 -080018 return 0;
19 // +1 is required because of the strict equality.
20 // For example if NumEntries is 48, we need to return 401.
21- return NextPowerOf2(NumEntries * 4 / 3 + 1);
22+ return static_cast<unsigned>(NextPowerOf2(NumEntries * 4 / 3 + 1));
23 }
24
25 void moveFromOldBuckets(BucketT *OldBucketsBegin, BucketT *OldBucketsEnd) {
James Kuszmaulb13e13f2023-11-22 20:44:04 -080026@@ -852,7 +852,7 @@ public:
James Kuszmaulcf324122023-01-14 14:07:17 -080027 // Reduce the number of buckets.
28 unsigned NewNumBuckets = 0;
29 if (OldNumEntries)
30- NewNumBuckets = std::max(64, 1 << (Log2_32_Ceil(OldNumEntries) + 1));
31+ NewNumBuckets = (std::max)(64, 1 << (Log2_32_Ceil(OldNumEntries) + 1));
32 if (NewNumBuckets == NumBuckets) {
33 this->BaseT::initEmpty();
34 return;
35diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h
James Kuszmaulb13e13f2023-11-22 20:44:04 -080036index 4559864ed231206b098936dae4fc378bfa986371..84f4d0931a30f4be29549354c85cb4c0489e14c9 100644
James Kuszmaulcf324122023-01-14 14:07:17 -080037--- a/llvm/include/llvm/ADT/SmallVector.h
38+++ b/llvm/include/llvm/ADT/SmallVector.h
James Kuszmaulb13e13f2023-11-22 20:44:04 -080039@@ -55,12 +55,12 @@ protected:
James Kuszmaulcf324122023-01-14 14:07:17 -080040
41 /// The maximum value of the Size_T used.
42 static constexpr size_t SizeTypeMax() {
43- return std::numeric_limits<Size_T>::max();
44+ return (std::numeric_limits<Size_T>::max)();
45 }
46
47 SmallVectorBase() = delete;
48 SmallVectorBase(void *FirstEl, size_t TotalCapacity)
49- : BeginX(FirstEl), Capacity(TotalCapacity) {}
50+ : BeginX(FirstEl), Capacity(static_cast<unsigned>(TotalCapacity)) {}
51
52 /// This is a helper for \a grow() that's out of line to reduce code
53 /// duplication. This function will report a fatal error if it can't grow at
James Kuszmaulb13e13f2023-11-22 20:44:04 -080054@@ -99,7 +99,7 @@ protected:
James Kuszmaulcf324122023-01-14 14:07:17 -080055 /// This does not construct or destroy any elements in the vector.
56 void set_size(size_t N) {
57 assert(N <= capacity());
58- Size = N;
59+ Size = static_cast<unsigned>(N);
60 }
61 };
62
James Kuszmaulb13e13f2023-11-22 20:44:04 -080063@@ -279,7 +279,7 @@ public:
James Kuszmaulcf324122023-01-14 14:07:17 -080064
65 size_type size_in_bytes() const { return size() * sizeof(T); }
66 size_type max_size() const {
67- return std::min(this->SizeTypeMax(), size_type(-1) / sizeof(T));
68+ return (std::min)(this->SizeTypeMax(), size_type(-1) / sizeof(T));
69 }
70
71 size_t capacity_in_bytes() const { return capacity() * sizeof(T); }
James Kuszmaulb13e13f2023-11-22 20:44:04 -080072@@ -467,7 +467,7 @@ void SmallVectorTemplateBase<T, TriviallyCopyable>::takeAllocationForGrow(
James Kuszmaulcf324122023-01-14 14:07:17 -080073 free(this->begin());
74
75 this->BeginX = NewElts;
76- this->Capacity = NewCapacity;
77+ this->Capacity = static_cast<unsigned>(NewCapacity);
78 }
79
80 /// SmallVectorTemplateBase<TriviallyCopyable = true> - This is where we put
James Kuszmaulb13e13f2023-11-22 20:44:04 -080081@@ -712,7 +712,7 @@ public:
James Kuszmaulcf324122023-01-14 14:07:17 -080082 }
83
84 // Assign over existing elements.
85- std::fill_n(this->begin(), std::min(NumElts, this->size()), Elt);
86+ std::fill_n(this->begin(), (std::min)(NumElts, this->size()), Elt);
87 if (NumElts > this->size())
88 std::uninitialized_fill_n(this->end(), NumElts - this->size(), Elt);
89 else if (NumElts < this->size())
90diff --git a/llvm/include/llvm/Support/ConvertUTF.h b/llvm/include/llvm/Support/ConvertUTF.h
James Kuszmaulb13e13f2023-11-22 20:44:04 -080091index 5c0e3009c25446a34882fb98329b1d955231bb39..72321022beb373945f7935ed72944fd68eb7d02f 100644
James Kuszmaulcf324122023-01-14 14:07:17 -080092--- a/llvm/include/llvm/Support/ConvertUTF.h
93+++ b/llvm/include/llvm/Support/ConvertUTF.h
James Kuszmaulb13e13f2023-11-22 20:44:04 -080094@@ -127,7 +127,7 @@ namespace llvm {
James Kuszmaulcf324122023-01-14 14:07:17 -080095 typedef unsigned int UTF32; /* at least 32 bits */
96 typedef unsigned short UTF16; /* at least 16 bits */
97 typedef unsigned char UTF8; /* typically 8 bits */
98-typedef unsigned char Boolean; /* 0 or 1 */
99+typedef bool Boolean; /* 0 or 1 */
100
101 /* Some fundamental constants */
102 #define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD
103diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800104index dc095941fdc8a9f2b3b822e6e014f0640676c0d3..0bd572d07fcbf2ff56998dbf366215068b62f527 100644
James Kuszmaulcf324122023-01-14 14:07:17 -0800105--- a/llvm/include/llvm/Support/MathExtras.h
106+++ b/llvm/include/llvm/Support/MathExtras.h
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800107@@ -311,26 +311,26 @@ template <> constexpr inline size_t CTLog2<1>() { return 0; }
James Kuszmaulcf324122023-01-14 14:07:17 -0800108 /// (32 bit edition.)
109 /// Ex. Log2_32(32) == 5, Log2_32(1) == 0, Log2_32(0) == -1, Log2_32(6) == 2
110 inline unsigned Log2_32(uint32_t Value) {
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800111- return 31 - llvm::countl_zero(Value);
112+ return static_cast<unsigned>(31 - llvm::countl_zero(Value));
James Kuszmaulcf324122023-01-14 14:07:17 -0800113 }
114
115 /// Return the floor log base 2 of the specified value, -1 if the value is zero.
116 /// (64 bit edition.)
117 inline unsigned Log2_64(uint64_t Value) {
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800118- return 63 - llvm::countl_zero(Value);
119+ return static_cast<unsigned>(63 - llvm::countl_zero(Value));
James Kuszmaulcf324122023-01-14 14:07:17 -0800120 }
121
122 /// Return the ceil log base 2 of the specified value, 32 if the value is zero.
123 /// (32 bit edition).
124 /// Ex. Log2_32_Ceil(32) == 5, Log2_32_Ceil(1) == 0, Log2_32_Ceil(6) == 3
125 inline unsigned Log2_32_Ceil(uint32_t Value) {
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800126- return 32 - llvm::countl_zero(Value - 1);
127+ return static_cast<unsigned>(32 - llvm::countl_zero(Value - 1));
James Kuszmaulcf324122023-01-14 14:07:17 -0800128 }
129
130 /// Return the ceil log base 2 of the specified value, 64 if the value is zero.
131 /// (64 bit edition.)
132 inline unsigned Log2_64_Ceil(uint64_t Value) {
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800133- return 64 - llvm::countl_zero(Value - 1);
134+ return static_cast<unsigned>(64 - llvm::countl_zero(Value - 1));
James Kuszmaulcf324122023-01-14 14:07:17 -0800135 }
136
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800137 /// A and B are either alignments or offsets. Return the minimum alignment that
138@@ -479,7 +479,7 @@ SaturatingAdd(T X, T Y, bool *ResultOverflowed = nullptr) {
James Kuszmaulcf324122023-01-14 14:07:17 -0800139 T Z = X + Y;
140 Overflowed = (Z < X || Z < Y);
141 if (Overflowed)
142- return std::numeric_limits<T>::max();
143+ return (std::numeric_limits<T>::max)();
144 else
145 return Z;
146 }
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800147@@ -492,7 +492,7 @@ std::enable_if_t<std::is_unsigned_v<T>, T> SaturatingAdd(T X, T Y, T Z,
148 bool Overflowed = false;
149 T XY = SaturatingAdd(X, Y, &Overflowed);
150 if (Overflowed)
151- return SaturatingAdd(std::numeric_limits<T>::max(), T(1), Args...);
152+ return SaturatingAdd((std::numeric_limits<T>::max)(), T(1), Args...);
153 return SaturatingAdd(XY, Z, Args...);
154 }
155
156@@ -516,7 +516,7 @@ SaturatingMultiply(T X, T Y, bool *ResultOverflowed = nullptr) {
James Kuszmaulcf324122023-01-14 14:07:17 -0800157 // Special case: if X or Y is 0, Log2_64 gives -1, and Log2Z
158 // will necessarily be less than Log2Max as desired.
159 int Log2Z = Log2_64(X) + Log2_64(Y);
160- const T Max = std::numeric_limits<T>::max();
161+ const T Max = (std::numeric_limits<T>::max)();
162 int Log2Max = Log2_64(Max);
163 if (Log2Z < Log2Max) {
164 return X * Y;
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800165@@ -636,9 +636,9 @@ std::enable_if_t<std::is_signed_v<T>, T> MulOverflow(T X, T Y, T &Result) {
James Kuszmaulcf324122023-01-14 14:07:17 -0800166 // Check how the max allowed absolute value (2^n for negative, 2^(n-1) for
167 // positive) divided by an argument compares to the other.
168 if (IsNegative)
169- return UX > (static_cast<U>(std::numeric_limits<T>::max()) + U(1)) / UY;
170+ return UX > (static_cast<U>((std::numeric_limits<T>::max)()) + U(1)) / UY;
171 else
172- return UX > (static_cast<U>(std::numeric_limits<T>::max())) / UY;
173+ return UX > (static_cast<U>((std::numeric_limits<T>::max)())) / UY;
174 }
175
176 } // End llvm namespace