@@ -127,6 +127,8 @@ static bool enumerateData(const Pointer &P, const Context &Ctx, Bits Offset,
127
127
bool Ok = true ;
128
128
129
129
for (const Record::Field &Fi : R->fields ()) {
130
+ if (Fi.isUnnamedBitField ())
131
+ continue ;
130
132
Pointer Elem = P.atField (Fi.Offset );
131
133
Bits BitOffset =
132
134
Offset + Bits (Layout.getFieldOffset (Fi.Decl ->getFieldIndex ()));
@@ -138,6 +140,10 @@ static bool enumerateData(const Pointer &P, const Context &Ctx, Bits Offset,
138
140
Layout.getBaseClassOffset (cast<CXXRecordDecl>(B.Decl ));
139
141
Bits BitOffset = Offset + Bits (Ctx.getASTContext ().toBits (ByteOffset));
140
142
Ok = Ok && enumerateData (Elem, Ctx, BitOffset, BitsToRead, F);
143
+ // FIXME: We should only (need to) do this when bitcasting OUT of the
144
+ // buffer, not when copying data into it.
145
+ if (Ok)
146
+ Elem.initialize ();
141
147
}
142
148
143
149
return Ok;
@@ -229,19 +235,29 @@ static bool readPointerToBuffer(const Context &Ctx, const Pointer &FromPtr,
229
235
FromPtr, Ctx, Buffer.size (),
230
236
[&](const Pointer &P, PrimType T, Bits BitOffset,
231
237
bool PackedBools) -> bool {
232
- // if (!P.isInitialized()) {
233
- // assert(false && "Implement uninitialized value tracking");
234
- // return ReturnOnUninit;
235
- // }
238
+ CharUnits ObjectReprChars = ASTCtx.getTypeSizeInChars (P.getType ());
239
+ Bits BitWidth = Bits (ASTCtx.toBits (ObjectReprChars));
240
+ Bits FullBitWidth = BitWidth;
241
+
242
+ if (const FieldDecl *FD = P.getField (); FD && FD->isBitField ()) {
243
+ BitWidth = Bits (std::min (FD->getBitWidthValue (ASTCtx),
244
+ (unsigned )FullBitWidth.getQuantity ()));
245
+ } else if (T == PT_Bool && PackedBools)
246
+ BitWidth = Bits (1 );
236
247
237
- // assert(P.isInitialized());
248
+ if (BitWidth.isZero ())
249
+ return true ;
250
+
251
+ if (!P.isInitialized ()) {
252
+ assert (false && " Implement uninitialized value tracking" );
253
+ return ReturnOnUninit;
254
+ }
255
+
256
+ assert (P.isInitialized ());
238
257
// nullptr_t is a PT_Ptr for us, but it's still not std::is_pointer_v.
239
258
if (T == PT_Ptr)
240
259
assert (false && " Implement casting to pointer types" );
241
260
242
- CharUnits ObjectReprChars = ASTCtx.getTypeSizeInChars (P.getType ());
243
- Bits BitWidth = Bits (ASTCtx.toBits (ObjectReprChars));
244
- Bits FullBitWidth = BitWidth;
245
261
auto Buff =
246
262
std::make_unique<std::byte[]>(ObjectReprChars.getQuantity ());
247
263
// Work around floating point types that contain unused padding bytes.
@@ -260,12 +276,6 @@ static bool readPointerToBuffer(const Context &Ctx, const Pointer &FromPtr,
260
276
swapBytes (Buff.get (), NumBits.roundToBytes ());
261
277
262
278
} else {
263
- if (const FieldDecl *FD = P.getField (); FD && FD->isBitField ())
264
- BitWidth = Bits (std::min (FD->getBitWidthValue (ASTCtx),
265
- (unsigned )FullBitWidth.getQuantity ()));
266
- else if (T == PT_Bool && PackedBools)
267
- BitWidth = Bits (1 );
268
-
269
279
BITCAST_TYPE_SWITCH (T, { P.deref <T>().bitcastToMemory (Buff.get ()); });
270
280
271
281
if (llvm::sys::IsBigEndianHost)
0 commit comments