James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1 | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 2 | From: PJ Reiniger <pj.reiniger@gmail.com> |
| 3 | Date: Sat, 7 May 2022 22:12:41 -0400 |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 4 | Subject: [PATCH 02/31] Wrap std::min/max calls in parens, for Windows warnings |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 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 +- |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 10 | llvm/include/llvm/Support/MathExtras.h | 18 +++++++++--------- |
| 11 | 4 files changed, 18 insertions(+), 18 deletions(-) |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 12 | |
| 13 | diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 14 | index 3ef6a7cd1b4b587e61fcb9475d9f3516018bf2ee..108193f04486425f3b7f039cd9d2004be6facafb 100644 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 15 | --- a/llvm/include/llvm/ADT/DenseMap.h |
| 16 | +++ b/llvm/include/llvm/ADT/DenseMap.h |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 17 | @@ -416,7 +416,7 @@ protected: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 18 | 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 Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 26 | @@ -852,7 +852,7 @@ public: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 27 | // 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; |
| 35 | diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 36 | index 4559864ed231206b098936dae4fc378bfa986371..84f4d0931a30f4be29549354c85cb4c0489e14c9 100644 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 37 | --- a/llvm/include/llvm/ADT/SmallVector.h |
| 38 | +++ b/llvm/include/llvm/ADT/SmallVector.h |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 39 | @@ -55,12 +55,12 @@ protected: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 40 | |
| 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 Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 54 | @@ -99,7 +99,7 @@ protected: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 55 | /// 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 Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 63 | @@ -279,7 +279,7 @@ public: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 64 | |
| 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 Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 72 | @@ -467,7 +467,7 @@ void SmallVectorTemplateBase<T, TriviallyCopyable>::takeAllocationForGrow( |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 73 | 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 Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 81 | @@ -712,7 +712,7 @@ public: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 82 | } |
| 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()) |
| 90 | diff --git a/llvm/include/llvm/Support/ConvertUTF.h b/llvm/include/llvm/Support/ConvertUTF.h |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 91 | index 5c0e3009c25446a34882fb98329b1d955231bb39..72321022beb373945f7935ed72944fd68eb7d02f 100644 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 92 | --- a/llvm/include/llvm/Support/ConvertUTF.h |
| 93 | +++ b/llvm/include/llvm/Support/ConvertUTF.h |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 94 | @@ -127,7 +127,7 @@ namespace llvm { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 95 | 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 |
| 103 | diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 104 | index dc095941fdc8a9f2b3b822e6e014f0640676c0d3..0bd572d07fcbf2ff56998dbf366215068b62f527 100644 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 105 | --- a/llvm/include/llvm/Support/MathExtras.h |
| 106 | +++ b/llvm/include/llvm/Support/MathExtras.h |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 107 | @@ -311,26 +311,26 @@ template <> constexpr inline size_t CTLog2<1>() { return 0; } |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 108 | /// (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 Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 111 | - return 31 - llvm::countl_zero(Value); |
| 112 | + return static_cast<unsigned>(31 - llvm::countl_zero(Value)); |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 113 | } |
| 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 Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 118 | - return 63 - llvm::countl_zero(Value); |
| 119 | + return static_cast<unsigned>(63 - llvm::countl_zero(Value)); |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 120 | } |
| 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 Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 126 | - return 32 - llvm::countl_zero(Value - 1); |
| 127 | + return static_cast<unsigned>(32 - llvm::countl_zero(Value - 1)); |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 128 | } |
| 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 Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 133 | - return 64 - llvm::countl_zero(Value - 1); |
| 134 | + return static_cast<unsigned>(64 - llvm::countl_zero(Value - 1)); |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 135 | } |
| 136 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 137 | /// 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 Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 139 | 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 Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 147 | @@ -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 Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 157 | // 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 Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 165 | @@ -636,9 +636,9 @@ std::enable_if_t<std::is_signed_v<T>, T> MulOverflow(T X, T Y, T &Result) { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 166 | // 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 |