@@ -77,6 +77,8 @@ struct CIRRecordLowering final {
7777 return astContext.toCharUnitsFromBits (bitOffset);
7878 }
7979
80+ void calculateZeroInit ();
81+
8082 CharUnits getSize (mlir::Type Ty) {
8183 return CharUnits::fromQuantity (dataLayout.layout .getTypeSize (Ty));
8284 }
@@ -177,18 +179,26 @@ void CIRRecordLowering::lower() {
177179 return ;
178180 }
179181
180- if (isa<CXXRecordDecl>(recordDecl)) {
181- cirGenTypes.getCGModule ().errorNYI (recordDecl->getSourceRange (),
182- " lower: class" );
183- return ;
184- }
185-
186182 assert (!cir::MissingFeatures::cxxSupport ());
187183
188184 CharUnits size = astRecordLayout.getSize ();
189185
190186 accumulateFields ();
191187
188+ if (const auto *cxxRecordDecl = dyn_cast<CXXRecordDecl>(recordDecl)) {
189+ if (cxxRecordDecl->getNumBases () > 0 ) {
190+ CIRGenModule &cgm = cirGenTypes.getCGModule ();
191+ cgm.errorNYI (recordDecl->getSourceRange (),
192+ " CIRRecordLowering::lower: derived CXXRecordDecl" );
193+ return ;
194+ }
195+ if (members.empty ()) {
196+ appendPaddingBytes (size);
197+ assert (!cir::MissingFeatures::bitfields ());
198+ return ;
199+ }
200+ }
201+
192202 llvm::stable_sort (members);
193203 // TODO: implement clipTailPadding once bitfields are implemented
194204 assert (!cir::MissingFeatures::bitfields ());
@@ -199,6 +209,7 @@ void CIRRecordLowering::lower() {
199209 insertPadding ();
200210 members.pop_back ();
201211
212+ calculateZeroInit ();
202213 fillOutputFields ();
203214}
204215
@@ -236,6 +247,19 @@ void CIRRecordLowering::accumulateFields() {
236247 }
237248}
238249
250+ void CIRRecordLowering::calculateZeroInit () {
251+ for (const MemberInfo &member : members) {
252+ if (member.kind == MemberInfo::InfoKind::Field) {
253+ if (!member.fieldDecl || isZeroInitializable (member.fieldDecl ))
254+ continue ;
255+ zeroInitializable = zeroInitializableAsBase = false ;
256+ return ;
257+ }
258+ // TODO(cir): handle base types
259+ assert (!cir::MissingFeatures::cxxSupport ());
260+ }
261+ }
262+
239263void CIRRecordLowering::determinePacked () {
240264 if (packed)
241265 return ;
@@ -295,7 +319,10 @@ CIRGenTypes::computeRecordLayout(const RecordDecl *rd, cir::RecordType *ty) {
295319 // If we're in C++, compute the base subobject type.
296320 if (llvm::isa<CXXRecordDecl>(rd) && !rd->isUnion () &&
297321 !rd->hasAttr <FinalAttr>()) {
298- cgm.errorNYI (rd->getSourceRange (), " computeRecordLayout: CXXRecordDecl" );
322+ if (lowering.astRecordLayout .getNonVirtualSize () !=
323+ lowering.astRecordLayout .getSize ()) {
324+ cgm.errorNYI (rd->getSourceRange (), " computeRecordLayout: CXXRecordDecl" );
325+ }
299326 }
300327
301328 // Fill in the record *after* computing the base type. Filling in the body
@@ -304,7 +331,9 @@ CIRGenTypes::computeRecordLayout(const RecordDecl *rd, cir::RecordType *ty) {
304331 assert (!cir::MissingFeatures::astRecordDeclAttr ());
305332 ty->complete (lowering.fieldTypes , lowering.packed , lowering.padded );
306333
307- auto rl = std::make_unique<CIRGenRecordLayout>(ty ? *ty : cir::RecordType ());
334+ auto rl = std::make_unique<CIRGenRecordLayout>(
335+ ty ? *ty : cir::RecordType (), (bool )lowering.zeroInitializable ,
336+ (bool )lowering.zeroInitializableAsBase );
308337
309338 assert (!cir::MissingFeatures::recordZeroInit ());
310339 assert (!cir::MissingFeatures::cxxSupport ());
0 commit comments