@@ -142,7 +142,7 @@ struct CIRRecordLowering final {
142142 std::vector<MemberInfo> members;
143143 // Output fields, consumed by CIRGenTypes::computeRecordLayout
144144 llvm::SmallVector<mlir::Type, 16 > fieldTypes;
145- llvm::DenseMap<const FieldDecl *, unsigned > fields ;
145+ llvm::DenseMap<const FieldDecl *, unsigned > fieldIdxMap ;
146146 cir::CIRDataLayout dataLayout;
147147
148148 LLVM_PREFERRED_TYPE (bool )
@@ -208,7 +208,8 @@ void CIRRecordLowering::fillOutputFields() {
208208 fieldTypes.push_back (member.data );
209209 if (member.kind == MemberInfo::InfoKind::Field) {
210210 if (member.fieldDecl )
211- fields[member.fieldDecl ->getCanonicalDecl ()] = fieldTypes.size () - 1 ;
211+ fieldIdxMap[member.fieldDecl ->getCanonicalDecl ()] =
212+ fieldTypes.size () - 1 ;
212213 // A field without storage must be a bitfield.
213214 assert (!cir::MissingFeatures::bitfields ());
214215 }
@@ -310,7 +311,7 @@ CIRGenTypes::computeRecordLayout(const RecordDecl *rd, cir::RecordType *ty) {
310311 assert (!cir::MissingFeatures::bitfields ());
311312
312313 // Add all the field numbers.
313- rl->fieldInfo .swap (lowering.fields );
314+ rl->fieldIdxMap .swap (lowering.fieldIdxMap );
314315
315316 // Dump the layout, if requested.
316317 if (getASTContext ().getLangOpts ().DumpRecordLayouts ) {
@@ -327,10 +328,7 @@ void CIRRecordLowering::lowerUnion() {
327328 bool seenNamedMember = false ;
328329
329330 // Iterate through the fields setting bitFieldInfo and the Fields array. Also
330- // locate the "most appropriate" storage type. The heuristic for finding the
331- // storage type isn't necessary, the first (non-0-length-bitfield) field's
332- // type would work fine and be simpler but would be different than what we've
333- // been doing and cause lit tests to change.
331+ // locate the "most appropriate" storage type.
334332 for (const FieldDecl *field : recordDecl->fields ()) {
335333 mlir::Type fieldType;
336334 if (field->isBitField ())
@@ -339,12 +337,13 @@ void CIRRecordLowering::lowerUnion() {
339337 else
340338 fieldType = getStorageType (field);
341339
342- fields[field->getCanonicalDecl ()] = 0 ;
340+ // This maps a field to its index. For unions, the index is always 0.
341+ fieldIdxMap[field->getCanonicalDecl ()] = 0 ;
343342
344343 // Compute zero-initializable status.
345344 // This union might not be zero initialized: it may contain a pointer to
346345 // data member which might have some exotic initialization sequence.
347- // If this is the case, then we aught not to try and come up with a "better"
346+ // If this is the case, then we ought not to try and come up with a "better"
348347 // type, it might not be very easy to come up with a Constant which
349348 // correctly initializes it.
350349 if (!seenNamedMember) {
@@ -380,9 +379,8 @@ void CIRRecordLowering::lowerUnion() {
380379
381380 if (layoutSize < getSize (storageType))
382381 storageType = getByteArrayType (layoutSize);
383-
384- // NOTE(cir): Defer padding calculations to the lowering process.
385- appendPaddingBytes (layoutSize - getSize (storageType));
382+ else
383+ appendPaddingBytes (layoutSize - getSize (storageType));
386384
387385 // Set packed if we need it.
388386 if (layoutSize % getAlignment (storageType))
0 commit comments