[flang-commits] [flang] [llvm] [Flang] Introduce common::numeric_limits (PR #228108)
Eugene Epshteyn via flang-commits
flang-commits at lists.llvm.org
Tue Oct 6 03:27:56 PDT 2026
================
@@ -304,5 +310,108 @@ using HostUnsignedIntType = typename HostUnsignedIntTypeHelper<BITS>::type;
template <int BITS>
using HostSignedIntType = typename HostSignedIntTypeHelper<BITS>::type;
+namespace detail {
+
+template <typename T> class numeric_limits_impl {
+public:
+ static constexpr bool is_specialized{false};
+};
+
+template <> class numeric_limits_impl<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}; }
+ static constexpr T lowest() { return min(); }
+};
+
+template <> class numeric_limits_impl<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};
+ }
+ static constexpr T lowest() { return min(); }
+};
+
+#if defined(__SIZEOF_INT128__)
+// Handle discrepancy of support of bit 128 bit integers by compiler and
+// standard library. The compiler may treat __int128 as a builtin type, but the
+// standard library does not define std::numeric_limits for it. Two cases are
+// known:
+//
+// 1. clang-cl supports __int128, but MSVC, and therefore its STL used by
+// clang-cl, does not.
+//
+// 2. Some versions of libstdc++ in strict mode (-std=c++NN)
+// intentionally removes any use of __int128, even though gcc does not make
+// such a distinction.
----------------
eugeneepshteyn wrote:
typos: "support of bit 128 bit integers" -> "support of 128-bit integers"; "Some versions of libstdc++ ... intentionally removes" -> "remove".
https://github.com/llvm/llvm-project/pull/228108
More information about the flang-commits
mailing list