[flang] [llvm] [Flang] Introduce *Value classes with unittests (PR #216958)
Michael Kruse via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 30 04:54:02 PDT 2026
================
@@ -305,4 +305,69 @@ template <int BITS>
using HostSignedIntType = typename HostSignedIntTypeHelper<BITS>::type;
} // namespace Fortran::common
+
+namespace std {
+// Specializing std::numeric_limits is an intended extension point for
+// user-defined type.
+template <> class numeric_limits<Fortran::common::UnsignedInt128> {
+public:
+ using T = Fortran::common::UnsignedInt128;
+
+ static constexpr bool is_specialized{true};
+ static constexpr bool is_signed{false};
+ static constexpr bool is_integer{true};
+
+ static constexpr T min() { return T{0, 0}; }
+ static constexpr T max() { return T{UINT64_MAX, UINT64_MAX}; }
+};
+
+template <> class numeric_limits<Fortran::common::SignedInt128> {
+public:
+ using T = Fortran::common::SignedInt128;
+
+ static constexpr bool is_specialized{true};
+ static constexpr bool is_signed{true};
+ static constexpr bool is_integer{true};
+
+ static constexpr T min() {
+ return T{static_cast<std::uint64_t>(INT64_MIN), 0};
+ }
+ static constexpr T max() {
+ return T{static_cast<std::uint64_t>(INT64_MAX), UINT64_MAX};
+ }
+};
+
+#if defined(__SIZEOF_INT128__) && defined(_MSVC_STL_VERSION)
+// clang-cl knows __int128 and will be used for (u)int128_t, but the MSVC STL
+// does not define stl::numeric_limits for it.
+
+template <> class numeric_limits<unsigned __int128> {
+public:
+ using T = unsigned __int128;
+
+ static constexpr bool is_specialized{true};
+ static constexpr bool is_signed{false};
+ static constexpr bool is_integer{true};
+
+ static constexpr T min() { return static_cast<T>(0); }
+ static constexpr T max() { return ~static_cast<T>(0); }
+};
+
+template <> class numeric_limits<__int128> {
+public:
+ using T = __int128;
+
+ static constexpr bool is_specialized{true};
+ static constexpr bool is_signed{true};
+ static constexpr bool is_integer{true};
+
+ static constexpr T min() {
+ return static_cast<T>(static_cast<unsigned __int128>(1) << 127u);
+ }
+ static constexpr T max() {
+ return static_cast<T>(~(static_cast<unsigned __int128>(1) << 127u));
+ }
+};
+#endif
----------------
Meinersbur wrote:
This means changing the `std::numeric_limits` to `Flang::common::numeric_limits` in several places. I considered specifying the `_MSVC_STL_VERSION` version that eventually defines in the `#if` once there is an MSVC STL that defines it the lesser evil.
I will make that change.
https://github.com/llvm/llvm-project/pull/216958
More information about the llvm-commits
mailing list