@@ -134,6 +134,10 @@ static bool enumerateData(const Pointer &P, const Context &Ctx, Bits Offset,
134134 Layout.getBaseClassOffset (cast<CXXRecordDecl>(B.Decl ));
135135 Bits BitOffset = Offset + Bits (Ctx.getASTContext ().toBits (ByteOffset));
136136 Ok = Ok && enumerateData (Elem, Ctx, BitOffset, F);
137+ // FIXME: We should only (need to) do this when bitcasting OUT of the
138+ // buffer, not when copying data into it.
139+ if (Ok)
140+ Elem.initialize ();
137141 }
138142
139143 return Ok;
@@ -225,19 +229,32 @@ static bool readPointerToBuffer(const Context &Ctx, const Pointer &FromPtr,
225229 FromPtr, Ctx,
226230 [&](const Pointer &P, PrimType T, Bits BitOffset,
227231 bool PackedBools) -> bool {
228- // if (!P.isInitialized()) {
229- // assert(false && "Implement uninitialized value tracking");
230- // return ReturnOnUninit;
231- // }
232+ CharUnits ObjectReprChars = ASTCtx.getTypeSizeInChars (P.getType ());
233+ Bits BitWidth = Bits (ASTCtx.toBits (ObjectReprChars));
234+ Bits FullBitWidth = BitWidth;
235+
236+ if (const FieldDecl *FD = P.getField (); FD && FD->isBitField ()) {
237+ // Unnamed bitfields should be skipped altogether.
238+ if (FD->isUnnamedBitField ())
239+ return true ;
240+ BitWidth = Bits (std::min (FD->getBitWidthValue (ASTCtx),
241+ (unsigned )FullBitWidth.getQuantity ()));
242+ } else if (T == PT_Bool && PackedBools)
243+ BitWidth = Bits (1 );
232244
233- // assert(P.isInitialized());
245+ if (BitWidth.isZero ())
246+ return true ;
247+
248+ if (!P.isInitialized ()) {
249+ assert (false && " Implement uninitialized value tracking" );
250+ return ReturnOnUninit;
251+ }
252+
253+ assert (P.isInitialized ());
234254 // nullptr_t is a PT_Ptr for us, but it's still not std::is_pointer_v.
235255 if (T == PT_Ptr)
236256 assert (false && " Implement casting to pointer types" );
237257
238- CharUnits ObjectReprChars = ASTCtx.getTypeSizeInChars (P.getType ());
239- Bits BitWidth = Bits (ASTCtx.toBits (ObjectReprChars));
240- Bits FullBitWidth = BitWidth;
241258 auto Buff =
242259 std::make_unique<std::byte[]>(ObjectReprChars.getQuantity ());
243260 // Work around floating point types that contain unused padding bytes.
@@ -256,12 +273,6 @@ static bool readPointerToBuffer(const Context &Ctx, const Pointer &FromPtr,
256273 swapBytes (Buff.get (), NumBits.roundToBytes ());
257274
258275 } else {
259- if (const FieldDecl *FD = P.getField (); FD && FD->isBitField ())
260- BitWidth = Bits (std::min (FD->getBitWidthValue (ASTCtx),
261- (unsigned )FullBitWidth.getQuantity ()));
262- else if (T == PT_Bool && PackedBools)
263- BitWidth = Bits (1 );
264-
265276 BITCAST_TYPE_SWITCH (T, { P.deref <T>().bitcastToMemory (Buff.get ()); });
266277
267278 if (llvm::sys::IsBigEndianHost)
0 commit comments