diff --git a/libc/src/__support/CPP/CMakeLists.txt b/libc/src/__support/CPP/CMakeLists.txt --- a/libc/src/__support/CPP/CMakeLists.txt +++ b/libc/src/__support/CPP/CMakeLists.txt @@ -47,7 +47,7 @@ add_header_library( limits HDRS - Limits.h + limits.h DEPENDS .uint ) diff --git a/libc/src/__support/CPP/Limits.h b/libc/src/__support/CPP/limits.h rename from libc/src/__support/CPP/Limits.h rename to libc/src/__support/CPP/limits.h --- a/libc/src/__support/CPP/Limits.h +++ b/libc/src/__support/CPP/limits.h @@ -16,60 +16,60 @@ namespace __llvm_libc { namespace cpp { -template class NumericLimits { +template class numeric_limits { public: static constexpr T max(); static constexpr T min(); }; -// TODO: Add NumericLimits specializations as needed for new types. +// TODO: Add numeric_limits specializations as needed for new types. -template <> class NumericLimits { +template <> class numeric_limits { public: static constexpr int max() { return INT_MAX; } static constexpr int min() { return INT_MIN; } }; -template <> class NumericLimits { +template <> class numeric_limits { public: static constexpr unsigned int max() { return UINT_MAX; } static constexpr unsigned int min() { return 0; } }; -template <> class NumericLimits { +template <> class numeric_limits { public: static constexpr long max() { return LONG_MAX; } static constexpr long min() { return LONG_MIN; } }; -template <> class NumericLimits { +template <> class numeric_limits { public: static constexpr unsigned long max() { return ULONG_MAX; } static constexpr unsigned long min() { return 0; } }; -template <> class NumericLimits { +template <> class numeric_limits { public: static constexpr long long max() { return LLONG_MAX; } static constexpr long long min() { return LLONG_MIN; } }; -template <> class NumericLimits { +template <> class numeric_limits { public: static constexpr unsigned long long max() { return ULLONG_MAX; } static constexpr unsigned long long min() { return 0; } }; -template <> class NumericLimits { +template <> class numeric_limits { public: static constexpr short max() { return SHRT_MAX; } static constexpr short min() { return SHRT_MIN; } }; -template <> class NumericLimits { +template <> class numeric_limits { public: static constexpr unsigned short max() { return USHRT_MAX; } static constexpr unsigned short min() { return 0; } }; -template <> class NumericLimits { +template <> class numeric_limits { public: static constexpr char max() { return CHAR_MAX; } static constexpr char min() { return CHAR_MIN; } }; -template <> class NumericLimits { +template <> class numeric_limits { public: static constexpr unsigned char max() { return UCHAR_MAX; } static constexpr unsigned char min() { return 0; } @@ -79,7 +79,7 @@ // provides limits of UInt128. // 2. On platforms where UInt128 resolves to __uint128_t, this specialization // allows us to unittest UInt<128>. -template <> class NumericLimits> { +template <> class numeric_limits> { public: static constexpr UInt<128> max() { return ~UInt<128>(0); } static constexpr UInt<128> min() { return 0; } @@ -87,7 +87,7 @@ #ifdef __SIZEOF_INT128__ // On platform where UInt128 resolves to __uint128_t, this specialization // provides the limits of UInt128. -template <> class NumericLimits<__uint128_t> { +template <> class numeric_limits<__uint128_t> { public: static constexpr __uint128_t max() { return ~__uint128_t(0); } static constexpr __uint128_t min() { return 0; } diff --git a/libc/src/__support/FPUtil/generic/FMod.h b/libc/src/__support/FPUtil/generic/FMod.h --- a/libc/src/__support/FPUtil/generic/FMod.h +++ b/libc/src/__support/FPUtil/generic/FMod.h @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_GENERIC_FMOD_H #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_GENERIC_FMOD_H -#include "src/__support/CPP/Limits.h" +#include "src/__support/CPP/limits.h" #include "src/__support/CPP/type_traits.h" #include "src/__support/FPUtil/FEnvImpl.h" #include "src/__support/FPUtil/FPBits.h" @@ -190,7 +190,7 @@ inline constexpr static intU_t execute(int exp_diff, int sides_zeroes_count, intU_t m_x, intU_t m_y) { if (exp_diff > sides_zeroes_count) { - intU_t inv_hy = (cpp::NumericLimits::max() / m_y); + intU_t inv_hy = (cpp::numeric_limits::max() / m_y); while (exp_diff > sides_zeroes_count) { exp_diff -= sides_zeroes_count; intU_t hd = diff --git a/libc/src/__support/str_to_float.h b/libc/src/__support/str_to_float.h --- a/libc/src/__support/str_to_float.h +++ b/libc/src/__support/str_to_float.h @@ -9,8 +9,8 @@ #ifndef LIBC_SRC_SUPPORT_STR_TO_FLOAT_H #define LIBC_SRC_SUPPORT_STR_TO_FLOAT_H -#include "src/__support/CPP/Limits.h" #include "src/__support/CPP/UInt128.h" +#include "src/__support/CPP/limits.h" #include "src/__support/FPUtil/FPBits.h" #include "src/__support/FPUtil/builtin_wrappers.h" #include "src/__support/ctype_utils.h" @@ -738,7 +738,7 @@ // The loop fills the mantissa with as many digits as it can hold const BitsType bitstype_max_div_by_base = - __llvm_libc::cpp::NumericLimits::max() / BASE; + cpp::numeric_limits::max() / BASE; while (true) { if (isdigit(*src)) { uint32_t digit = *src - '0'; @@ -828,7 +828,7 @@ // The loop fills the mantissa with as many digits as it can hold const BitsType bitstype_max_div_by_base = - __llvm_libc::cpp::NumericLimits::max() / BASE; + cpp::numeric_limits::max() / BASE; while (true) { if (isalnum(*src)) { uint32_t digit = b36_char_to_int(*src); diff --git a/libc/src/__support/str_to_integer.h b/libc/src/__support/str_to_integer.h --- a/libc/src/__support/str_to_integer.h +++ b/libc/src/__support/str_to_integer.h @@ -9,7 +9,7 @@ #ifndef LIBC_SRC_SUPPORT_STR_TO_INTEGER_H #define LIBC_SRC_SUPPORT_STR_TO_INTEGER_H -#include "src/__support/CPP/Limits.h" +#include "src/__support/CPP/limits.h" #include "src/__support/ctype_utils.h" #include #include @@ -92,15 +92,14 @@ src = src + 2; } - constexpr bool IS_UNSIGNED = (__llvm_libc::cpp::NumericLimits::min() == 0); + constexpr bool IS_UNSIGNED = (cpp::numeric_limits::min() == 0); const bool is_positive = (result_sign == '+'); unsigned long long constexpr NEGATIVE_MAX = - !IS_UNSIGNED ? static_cast( - __llvm_libc::cpp::NumericLimits::max()) + - 1 - : __llvm_libc::cpp::NumericLimits::max(); + !IS_UNSIGNED + ? static_cast(cpp::numeric_limits::max()) + 1 + : cpp::numeric_limits::max(); unsigned long long const abs_max = - (is_positive ? __llvm_libc::cpp::NumericLimits::max() : NEGATIVE_MAX); + (is_positive ? cpp::numeric_limits::max() : NEGATIVE_MAX); unsigned long long const abs_max_div_by_base = abs_max / base; while (isalnum(*src)) { int cur_digit = b36_char_to_int(*src); @@ -137,9 +136,9 @@ if (result == abs_max) { if (is_positive || IS_UNSIGNED) - return __llvm_libc::cpp::NumericLimits::max(); + return cpp::numeric_limits::max(); else // T is signed and there is a negative overflow - return __llvm_libc::cpp::NumericLimits::min(); + return cpp::numeric_limits::min(); } return is_positive ? static_cast(result) : -static_cast(result); diff --git a/libc/src/stdio/printf_core/converter_utils.h b/libc/src/stdio/printf_core/converter_utils.h --- a/libc/src/stdio/printf_core/converter_utils.h +++ b/libc/src/stdio/printf_core/converter_utils.h @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_SRC_STDIO_PRINTF_CORE_CONVERTER_UTILS_H #define LLVM_LIBC_SRC_STDIO_PRINTF_CORE_CONVERTER_UTILS_H -#include "src/__support/CPP/Limits.h" +#include "src/__support/CPP/limits.h" #include "src/stdio/printf_core/core_structs.h" #include @@ -21,23 +21,23 @@ inline uintmax_t apply_length_modifier(uintmax_t num, LengthModifier lm) { switch (lm) { case LengthModifier::none: - return num & cpp::NumericLimits::max(); + return num & cpp::numeric_limits::max(); case LengthModifier::l: - return num & cpp::NumericLimits::max(); + return num & cpp::numeric_limits::max(); case LengthModifier::ll: case LengthModifier::L: - return num & cpp::NumericLimits::max(); + return num & cpp::numeric_limits::max(); case LengthModifier::h: - return num & cpp::NumericLimits::max(); + return num & cpp::numeric_limits::max(); case LengthModifier::hh: - return num & cpp::NumericLimits::max(); + return num & cpp::numeric_limits::max(); case LengthModifier::z: - return num & cpp::NumericLimits::max(); + return num & cpp::numeric_limits::max(); case LengthModifier::t: // We don't have unsigned ptrdiff so uintptr_t is used, since we need an // unsigned type and ptrdiff is usually the same size as a pointer. static_assert(sizeof(ptrdiff_t) == sizeof(uintptr_t)); - return num & cpp::NumericLimits::max(); + return num & cpp::numeric_limits::max(); case LengthModifier::j: return num; // j is intmax, so no mask is necessary. } diff --git a/libc/src/stdio/printf_core/write_int_converter.h b/libc/src/stdio/printf_core/write_int_converter.h --- a/libc/src/stdio/printf_core/write_int_converter.h +++ b/libc/src/stdio/printf_core/write_int_converter.h @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_SRC_STDIO_PRINTF_CORE_WRITE_INT_CONVERTER_H #define LLVM_LIBC_SRC_STDIO_PRINTF_CORE_WRITE_INT_CONVERTER_H -#include "src/__support/CPP/Limits.h" +#include "src/__support/CPP/limits.h" #include "src/stdio/printf_core/core_structs.h" #include "src/stdio/printf_core/writer.h" diff --git a/libc/test/src/__support/CPP/limits_test.cpp b/libc/test/src/__support/CPP/limits_test.cpp --- a/libc/test/src/__support/CPP/limits_test.cpp +++ b/libc/test/src/__support/CPP/limits_test.cpp @@ -6,39 +6,40 @@ // //===----------------------------------------------------------------------===// -#include "src/__support/CPP/Limits.h" #include "src/__support/CPP/UInt.h" +#include "src/__support/CPP/limits.h" #include "utils/UnitTest/Test.h" +namespace __llvm_libc { + // This just checks against the C spec, almost all implementations will surpass // this. TEST(LlvmLibcLimitsTest, LimitsFollowSpec) { - ASSERT_EQ(__llvm_libc::cpp::NumericLimits::max(), INT_MAX); - ASSERT_EQ(__llvm_libc::cpp::NumericLimits::min(), INT_MIN); + ASSERT_EQ(cpp::numeric_limits::max(), INT_MAX); + ASSERT_EQ(cpp::numeric_limits::min(), INT_MIN); - ASSERT_EQ(__llvm_libc::cpp::NumericLimits::max(), UINT_MAX); + ASSERT_EQ(cpp::numeric_limits::max(), UINT_MAX); - ASSERT_EQ(__llvm_libc::cpp::NumericLimits::max(), LONG_MAX); - ASSERT_EQ(__llvm_libc::cpp::NumericLimits::min(), LONG_MIN); + ASSERT_EQ(cpp::numeric_limits::max(), LONG_MAX); + ASSERT_EQ(cpp::numeric_limits::min(), LONG_MIN); - ASSERT_EQ(__llvm_libc::cpp::NumericLimits::max(), ULONG_MAX); + ASSERT_EQ(cpp::numeric_limits::max(), ULONG_MAX); - ASSERT_EQ(__llvm_libc::cpp::NumericLimits::max(), LLONG_MAX); - ASSERT_EQ(__llvm_libc::cpp::NumericLimits::min(), LLONG_MIN); + ASSERT_EQ(cpp::numeric_limits::max(), LLONG_MAX); + ASSERT_EQ(cpp::numeric_limits::min(), LLONG_MIN); - ASSERT_EQ(__llvm_libc::cpp::NumericLimits::max(), - ULLONG_MAX); + ASSERT_EQ(cpp::numeric_limits::max(), ULLONG_MAX); } TEST(LlvmLibcLimitsTest, UInt128Limits) { - auto umax128 = - __llvm_libc::cpp::NumericLimits<__llvm_libc::cpp::UInt<128>>::max(); - auto umax64 = __llvm_libc::cpp::UInt<128>( - __llvm_libc::cpp::NumericLimits::max()); + auto umax128 = cpp::numeric_limits<__llvm_libc::cpp::UInt<128>>::max(); + auto umax64 = + __llvm_libc::cpp::UInt<128>(cpp::numeric_limits::max()); EXPECT_GT(umax128, umax64); ASSERT_EQ(~__llvm_libc::cpp::UInt<128>(0), umax128); #ifdef __SIZEOF_INT128__ - ASSERT_EQ(~__uint128_t(0), - __llvm_libc::cpp::NumericLimits<__uint128_t>::max()); + ASSERT_EQ(~__uint128_t(0), cpp::numeric_limits<__uint128_t>::max()); #endif } + +} // namespace __llvm_libc diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel --- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel @@ -71,7 +71,7 @@ cc_library( name = "__support_cpp_limits", - hdrs = ["src/__support/CPP/Limits.h"], + hdrs = ["src/__support/CPP/limits.h"], deps = [":libc_root", "__support_cpp_uint"], )