diff --git a/llvm/include/llvm/ADT/bit.h b/llvm/include/llvm/ADT/bit.h --- a/llvm/include/llvm/ADT/bit.h +++ b/llvm/include/llvm/ADT/bit.h @@ -16,10 +16,13 @@ #include "llvm/Support/Compiler.h" #include -#include #include #include +#if !__has_builtin(__builtin_bit_cast) +#include +#endif + #ifdef _MSC_VER // Declare these intrinsics manually rather including intrin.h. It's very // expensive, and bit.h is popular via MathExtras.h. @@ -44,9 +47,13 @@ typename = std::enable_if_t::value>, typename = std::enable_if_t::value>> [[nodiscard]] inline To bit_cast(const From &from) noexcept { +#if __has_builtin(__builtin_bit_cast) + return __builtin_bit_cast(To, from); +#else To to; std::memcpy(&to, &from, sizeof(To)); return to; +#endif } template >>