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