[libc] [llvm] [libc][fenv] Refactor x86 fenv implementations to make it work for various fenv_t. (PR #165015)

via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 9 08:12:39 PST 2025


================
@@ -43,16 +53,30 @@ bit_cast(const From &from) {
   To to{};
   char *dst = reinterpret_cast<char *>(&to);
   const char *src = reinterpret_cast<const char *>(&from);
-#if __has_builtin(__builtin_memcpy_inline)
-  __builtin_memcpy_inline(dst, src, sizeof(To));
-#else
-  for (unsigned i = 0; i < sizeof(To); ++i)
-    dst[i] = src[i];
-#endif // __has_builtin(__builtin_memcpy_inline)
+  inline_copy<sizeof(From)>(src, dst);
   return to;
 #endif // __has_builtin(__builtin_bit_cast)
 }
 
+// The following simple bit copy from a smaller type to maybe-larger type.
+template <typename To, typename From>
+LIBC_INLINE constexpr cpp::enable_if_t<
+    (sizeof(To) >= sizeof(From)) &&
+        cpp::is_trivially_constructible<To>::value &&
+        cpp::is_trivially_copyable<To>::value &&
+        cpp::is_trivially_copyable<From>::value,
+    void>
+bit_copy(const From &from, To &to) {
+  MSAN_UNPOISON(&from, sizeof(From));
+  if constexpr (sizeof(To) == sizeof(From)) {
+    to = bit_cast<To>(from);
----------------
lntue wrote:

Removed.

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


More information about the llvm-commits mailing list