[libc] [llvm] [libc] Remove UB specializations of type traits for `BigInt` (PR #84035)

Guillaume Chatelet via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 7 01:40:18 PST 2024


================
@@ -38,7 +38,8 @@ TestLogger &operator<<(TestLogger &logger, Location Loc) {
 // When the value is UInt128, __uint128_t or wider, show its hexadecimal
 // digits.
 template <typename T>
-cpp::enable_if_t<cpp::is_integral_v<T> && (sizeof(T) > sizeof(uint64_t)),
+cpp::enable_if_t<(cpp::is_integral_v<T> && (sizeof(T) > sizeof(uint64_t))) ||
+                     cpp::is_big_int_v<T>,
----------------
gchatelet wrote:

Quoting [cpp_reference for std::is_integral](https://en.cppreference.com/w/cpp/types/is_integral#:~:text=Provides%20the%20member,behavior%20is%20undefined.):

> _Provides the member constant value which is equal to true, if T is the type bool, char, char8_t(since C++20), char16_t, char32_t, wchar_t, short, int, long, long long, or any implementation-defined extended integer types, including any signed, unsigned, and cv-qualified variants. Otherwise, value is equal to false._
>
> _If the program adds specializations for std::is_integral or std::is_integral_v, the behavior is undefined._

This means that `BigInt` is `false` for `is_integral` (that's the purpose of this patch)
This also means that `__int128_t` / `__uint128_t` is `true`.

So `cpp::is_integral_v<T> && (sizeof(T) > sizeof(uint64_t)))` means `__int128_t` or `__uint128_t`.
And `cpp::is_big_int_v<T>` means `BigInt` instantiation.

https://github.com/llvm/llvm-project/pull/84035


More information about the llvm-commits mailing list