@@ -134,6 +134,10 @@ static bool enumerateData(const Pointer &P, const Context &Ctx, Bits Offset,
134
134
Layout.getBaseClassOffset (cast<CXXRecordDecl>(B.Decl ));
135
135
Bits BitOffset = Offset + Bits (Ctx.getASTContext ().toBits (ByteOffset));
136
136
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 ();
137
141
}
138
142
139
143
return Ok;
@@ -225,19 +229,32 @@ static bool readPointerToBuffer(const Context &Ctx, const Pointer &FromPtr,
225
229
FromPtr, Ctx,
226
230
[&](const Pointer &P, PrimType T, Bits BitOffset,
227
231
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 );
232
244
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 ());
234
254
// nullptr_t is a PT_Ptr for us, but it's still not std::is_pointer_v.
235
255
if (T == PT_Ptr)
236
256
assert (false && " Implement casting to pointer types" );
237
257
238
- CharUnits ObjectReprChars = ASTCtx.getTypeSizeInChars (P.getType ());
239
- Bits BitWidth = Bits (ASTCtx.toBits (ObjectReprChars));
240
- Bits FullBitWidth = BitWidth;
241
258
auto Buff =
242
259
std::make_unique<std::byte[]>(ObjectReprChars.getQuantity ());
243
260
// Work around floating point types that contain unused padding bytes.
@@ -256,12 +273,6 @@ static bool readPointerToBuffer(const Context &Ctx, const Pointer &FromPtr,
256
273
swapBytes (Buff.get (), NumBits.roundToBytes ());
257
274
258
275
} 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
-
265
276
BITCAST_TYPE_SWITCH (T, { P.deref <T>().bitcastToMemory (Buff.get ()); });
266
277
267
278
if (llvm::sys::IsBigEndianHost)
0 commit comments