@@ -123,6 +123,8 @@ static bool enumerateData(const Pointer &P, const Context &Ctx, Bits Offset,
123123 bool Ok = true ;
124124
125125 for (const Record::Field &Fi : R->fields ()) {
126+ if (Fi.isUnnamedBitField ())
127+ continue ;
126128 Pointer Elem = P.atField (Fi.Offset );
127129 Bits BitOffset =
128130 Offset + Bits (Layout.getFieldOffset (Fi.Decl ->getFieldIndex ()));
@@ -134,6 +136,10 @@ static bool enumerateData(const Pointer &P, const Context &Ctx, Bits Offset,
134136 Layout.getBaseClassOffset (cast<CXXRecordDecl>(B.Decl ));
135137 Bits BitOffset = Offset + Bits (Ctx.getASTContext ().toBits (ByteOffset));
136138 Ok = Ok && enumerateData (Elem, Ctx, BitOffset, F);
139+ // FIXME: We should only (need to) do this when bitcasting OUT of the
140+ // buffer, not when copying data into it.
141+ if (Ok)
142+ Elem.initialize ();
137143 }
138144
139145 return Ok;
@@ -225,19 +231,29 @@ static bool readPointerToBuffer(const Context &Ctx, const Pointer &FromPtr,
225231 FromPtr, Ctx,
226232 [&](const Pointer &P, PrimType T, Bits BitOffset,
227233 bool PackedBools) -> bool {
228- // if (!P.isInitialized()) {
229- // assert(false && "Implement uninitialized value tracking");
230- // return ReturnOnUninit;
231- // }
234+ CharUnits ObjectReprChars = ASTCtx.getTypeSizeInChars (P.getType ());
235+ Bits BitWidth = Bits (ASTCtx.toBits (ObjectReprChars));
236+ Bits FullBitWidth = BitWidth;
237+
238+ if (const FieldDecl *FD = P.getField (); FD && FD->isBitField ()) {
239+ BitWidth = Bits (std::min (FD->getBitWidthValue (ASTCtx),
240+ (unsigned )FullBitWidth.getQuantity ()));
241+ } else if (T == PT_Bool && PackedBools)
242+ BitWidth = Bits (1 );
232243
233- // assert(P.isInitialized());
244+ if (BitWidth.isZero ())
245+ return true ;
246+
247+ if (!P.isInitialized ()) {
248+ assert (false && " Implement uninitialized value tracking" );
249+ return ReturnOnUninit;
250+ }
251+
252+ assert (P.isInitialized ());
234253 // nullptr_t is a PT_Ptr for us, but it's still not std::is_pointer_v.
235254 if (T == PT_Ptr)
236255 assert (false && " Implement casting to pointer types" );
237256
238- CharUnits ObjectReprChars = ASTCtx.getTypeSizeInChars (P.getType ());
239- Bits BitWidth = Bits (ASTCtx.toBits (ObjectReprChars));
240- Bits FullBitWidth = BitWidth;
241257 auto Buff =
242258 std::make_unique<std::byte[]>(ObjectReprChars.getQuantity ());
243259 // Work around floating point types that contain unused padding bytes.
@@ -256,12 +272,6 @@ static bool readPointerToBuffer(const Context &Ctx, const Pointer &FromPtr,
256272 swapBytes (Buff.get (), NumBits.roundToBytes ());
257273
258274 } 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-
265275 BITCAST_TYPE_SWITCH (T, { P.deref <T>().bitcastToMemory (Buff.get ()); });
266276
267277 if (llvm::sys::IsBigEndianHost)
0 commit comments