[libc-commits] [PATCH] D148739: [libc] Use __builtin_bit_cast only when src and dest types are trivially copyable

Mikhail Ramalho via Phabricator via libc-commits libc-commits at lists.llvm.org
Wed Apr 19 15:49:10 PDT 2023


mikhail.ramalho added inline comments.


================
Comment at: libc/src/__support/CPP/bit.h:14
 
+#include <type_traits>
+
----------------
sivachandra wrote:
> We cannot use the C++ standard library in the runtime components of the libc. Would marking the copy constructor with `= default` solve your problem: https://github.com/llvm/llvm-project/blob/main/libc/src/__support/UInt.h#L40
Not really... We get the following error:
```
/home/root/llvm-project/libc/src/__support/CPP/bit.h:29:10: error: __builtin_bit_cast destination type must be trivially copyable
  return __builtin_bit_cast(To, from);
         ^
/home/root/llvm-project/libc/src/__support/FPUtil/FPBits.h:111:50: note: in instantiation of function template specialization '__llvm_libc::cpp::bit_cast<__llvm_libc::cpp::UInt<128>, long double>' requested here
  constexpr explicit FPBits(XType x) : bits(cpp::bit_cast<UIntType>(x)) {}
                                                 ^
/home/root/llvm-project/libc/src/__support/FPUtil/NearestIntegerOperations.h:56:13: note: in instantiation of function template specialization '__llvm_libc::fputil::FPBits<long double>::FPBits<long double, 0>' requested here
  FPBits<T> bits(x);
            ^
/home/root/llvm-project/libc/src/math/generic/ceill.cpp:16:18: note: in instantiation of function template specialization '__llvm_libc::fputil::ceil<long double, 0>' requested here
  return fputil::ceil(x);
```

Maybe can use the compiler builtin __is_trivially_copyable (like https://github.com/llvm/llvm-project/blob/main/libcxx/include/__type_traits/is_trivially_copyable.h) and add it to `libc/src/__support/CPP/type_traits.h`? WDYT?



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148739/new/

https://reviews.llvm.org/D148739



More information about the libc-commits mailing list