[clang] [clang][bytecode] Start implementing __builtin_bit_cast (PR #112126)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 30 06:39:50 PDT 2024


Timm =?utf-8?q?Bäder?= <tbaeder at redhat.com>,
Timm =?utf-8?q?Bäder?= <tbaeder at redhat.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/112126 at github.com>


================
@@ -154,6 +154,18 @@ template <unsigned Bits, bool Signed> class Integral final {
     return Compare(V, RHS.V);
   }
 
+  void bitcastToMemory(std::byte *Dest) const {
+    std::memcpy(Dest, &V, sizeof(V));
+  }
+
+  static Integral bitcastFromMemory(const std::byte *Src, unsigned BitWidth) {
+    assert(BitWidth == sizeof(ReprT) * 8);
+    ReprT V;
+
+    std::memcpy(&V, Src, sizeof(ReprT));
----------------
AaronBallman wrote:

Can we add an assert somewhere that `ReprT` will always be trivially copyable?

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


More information about the cfe-commits mailing list