[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:50:05 PST 2024


================
@@ -51,8 +52,10 @@ LIBC_INLINE constexpr To bit_cast(const From &from) {
 #endif // LIBC_HAS_BUILTIN(__builtin_bit_cast)
 }
 
-template <typename T, typename = cpp::enable_if_t<cpp::is_unsigned_v<T>>>
-[[nodiscard]] LIBC_INLINE constexpr bool has_single_bit(T value) {
+template <typename T>
+[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>,
+                                                     bool>
+has_single_bit(T value) {
----------------
gchatelet wrote:

All our functions are `inline`. This means that the compiler can change how the value is passed to the function. That is, we don't care about passing by value or ref.

The only thing we need to make sure is that the type is `[[trivial_abi]]` ([blog article](https://quuxplusone.github.io/blog/2018/05/02/trivial-abi-101/)), otherwise the compiler is forced to pass by ref to be able to call the destructor when there is one. This is true even if the signature of the function passes the argument by value. So technically we'd need to annotate `BigInt` and `DoubleDouble` with `[[clang::trivial_abi]]` (or its GCC equivalent). We can also `static_assert<cpp::is_trivial_v<T>>` for `DoubleDouble` and `DyadicFloat<128>`.

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


More information about the llvm-commits mailing list