diff options
Diffstat (limited to 'llvm/lib/Support/NativeFormatting.cpp')
-rw-r--r-- | llvm/lib/Support/NativeFormatting.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/llvm/lib/Support/NativeFormatting.cpp b/llvm/lib/Support/NativeFormatting.cpp index 8a69f7513255..6e8137c405b8 100644 --- a/llvm/lib/Support/NativeFormatting.cpp +++ b/llvm/lib/Support/NativeFormatting.cpp @@ -14,6 +14,8 @@ #include "llvm/Support/MathExtras.h" #include "llvm/Support/raw_ostream.h" +#include <cmath> + #if defined(_WIN32) && !defined(__MINGW32__) #include <float.h> // For _fpclass in llvm::write_double. #endif @@ -53,7 +55,7 @@ static void writeWithCommas(raw_ostream &S, ArrayRef<char> Buffer) { template <typename T> static void write_unsigned_impl(raw_ostream &S, T N, size_t MinDigits, IntegerStyle Style, bool IsNegative) { - static_assert(std::is_unsigned<T>::value, "Value is not unsigned!"); + static_assert(std::is_unsigned_v<T>, "Value is not unsigned!"); char NumberBuffer[128]; std::memset(NumberBuffer, '0', sizeof(NumberBuffer)); @@ -90,7 +92,7 @@ static void write_unsigned(raw_ostream &S, T N, size_t MinDigits, template <typename T> static void write_signed(raw_ostream &S, T N, size_t MinDigits, IntegerStyle Style) { - static_assert(std::is_signed<T>::value, "Value is not signed!"); + static_assert(std::is_signed_v<T>, "Value is not signed!"); using UnsignedT = std::make_unsigned_t<T>; @@ -134,12 +136,12 @@ void llvm::write_integer(raw_ostream &S, long long N, size_t MinDigits, } void llvm::write_hex(raw_ostream &S, uint64_t N, HexPrintStyle Style, - Optional<size_t> Width) { + std::optional<size_t> Width) { const size_t kMaxWidth = 128u; size_t W = std::min(kMaxWidth, Width.value_or(0u)); - unsigned Nibbles = (64 - countLeadingZeros(N) + 3) / 4; + unsigned Nibbles = (llvm::bit_width(N) + 3) / 4; bool Prefix = (Style == HexPrintStyle::PrefixLower || Style == HexPrintStyle::PrefixUpper); bool Upper = @@ -149,7 +151,7 @@ void llvm::write_hex(raw_ostream &S, uint64_t N, HexPrintStyle Style, std::max(static_cast<unsigned>(W), std::max(1u, Nibbles) + PrefixChars); char NumberBuffer[kMaxWidth]; - ::memset(NumberBuffer, '0', llvm::array_lengthof(NumberBuffer)); + ::memset(NumberBuffer, '0', std::size(NumberBuffer)); if (Prefix) NumberBuffer[1] = 'x'; char *EndPtr = NumberBuffer + NumChars; @@ -164,7 +166,7 @@ void llvm::write_hex(raw_ostream &S, uint64_t N, HexPrintStyle Style, } void llvm::write_double(raw_ostream &S, double N, FloatStyle Style, - Optional<size_t> Precision) { + std::optional<size_t> Precision) { size_t Prec = Precision.value_or(getDefaultPrecision(Style)); if (std::isnan(N)) { |