[clang] [clang][bytecode] Handle bitcasts involving bitfields (PR #116843)

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 20 08:01:37 PST 2024


================
@@ -362,22 +279,28 @@ bool clang::interp::DoBitCast(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
   assert(Ptr.isBlockPointer());
   assert(Buff);
 
-  BitcastBuffer Buffer;
+  size_t BitSize = BuffSize * 8;
+  BitcastBuffer Buffer(BitSize);
   if (!CheckBitcastType(S, OpPC, Ptr.getType(), /*IsToType=*/false))
     return false;
 
   bool Success = readPointerToBuffer(S.getContext(), Ptr, Buffer,
                                      /*ReturnOnUninit=*/false);
-  assert(Buffer.size() == BuffSize * 8);
-
   HasIndeterminateBits = !Buffer.allInitialized();
-  std::memcpy(Buff, Buffer.data(), BuffSize);
+
+  const ASTContext &ASTCtx = S.getASTContext();
+  Endian TargetEndianness =
+      ASTCtx.getTargetInfo().isLittleEndian() ? Endian::Little : Endian::Big;
+  auto B = Buffer.copyBits(0, BitSize, BitSize, TargetEndianness);
+
+  std::memcpy(Buff, B.get(), BuffSize);
 
   if (llvm::sys::IsBigEndianHost)
     swapBytes(Buff, BuffSize);
 
   return Success;
 }
+/// ---------------------------------------------------------------------------------------------------------------------
----------------
tbaederr wrote:

Just a separator for me, I'll remove it.

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


More information about the cfe-commits mailing list