@@ -103,7 +103,8 @@ std::string CIRGenTypes::getRecordTypeName(const clang::RecordDecl *recordDecl,
103103 policy.SuppressTagKeyword = true ;
104104
105105 if (recordDecl->getIdentifier ())
106- astContext.getRecordType (recordDecl).print (outStream, policy);
106+ QualType (astContext.getCanonicalTagType (recordDecl))
107+ .print (outStream, policy);
107108 else if (auto *typedefNameDecl = recordDecl->getTypedefNameForAnonDecl ())
108109 typedefNameDecl->printQualifiedName (outStream, policy);
109110 else
@@ -138,7 +139,7 @@ isSafeToConvert(const RecordDecl *rd, CIRGenTypes &cgt,
138139 if (!alreadyChecked.insert (rd).second )
139140 return true ;
140141
141- const Type *key = cgt.getASTContext ().getTagDeclType (rd).getTypePtr ();
142+ const Type *key = cgt.getASTContext ().getCanonicalTagType (rd).getTypePtr ();
142143
143144 // If this type is already laid out, converting it is a noop.
144145 if (cgt.isRecordLayoutComplete (key))
@@ -182,7 +183,8 @@ isSafeToConvert(QualType qt, CIRGenTypes &cgt,
182183
183184 // If this is a record, check it.
184185 if (const auto *rt = qt->getAs <RecordType>())
185- return isSafeToConvert (rt->getDecl (), cgt, alreadyChecked);
186+ return isSafeToConvert (rt->getOriginalDecl ()->getDefinitionOrSelf (), cgt,
187+ alreadyChecked);
186188
187189 // If this is an array, check the elements, which are embedded inline.
188190 if (const auto *at = cgt.getASTContext ().getAsArrayType (qt))
@@ -210,7 +212,7 @@ static bool isSafeToConvert(const RecordDecl *rd, CIRGenTypes &cgt) {
210212mlir::Type CIRGenTypes::convertRecordDeclType (const clang::RecordDecl *rd) {
211213 // TagDecl's are not necessarily unique, instead use the (clang) type
212214 // connected to the decl.
213- const Type *key = astContext.getTagDeclType (rd).getTypePtr ();
215+ const Type *key = astContext.getCanonicalTagType (rd).getTypePtr ();
214216 cir::RecordType entry = recordDeclTypes[key];
215217
216218 // If we don't have an entry for this record yet, create one.
@@ -242,7 +244,10 @@ mlir::Type CIRGenTypes::convertRecordDeclType(const clang::RecordDecl *rd) {
242244 for (const auto &base : cxxRecordDecl->bases ()) {
243245 if (base.isVirtual ())
244246 continue ;
245- convertRecordDeclType (base.getType ()->castAs <RecordType>()->getDecl ());
247+ convertRecordDeclType (base.getType ()
248+ ->castAs <RecordType>()
249+ ->getOriginalDecl ()
250+ ->getDefinitionOrSelf ());
246251 }
247252 }
248253
@@ -275,7 +280,8 @@ mlir::Type CIRGenTypes::convertType(QualType type) {
275280
276281 // Process record types before the type cache lookup.
277282 if (const auto *recordType = dyn_cast<RecordType>(type))
278- return convertRecordDeclType (recordType->getDecl ());
283+ return convertRecordDeclType (
284+ recordType->getOriginalDecl ()->getDefinitionOrSelf ());
279285
280286 // Has the type already been processed?
281287 TypeCacheTy::iterator tci = typeCache.find (ty);
@@ -457,7 +463,8 @@ mlir::Type CIRGenTypes::convertType(QualType type) {
457463 }
458464
459465 case Type::Enum: {
460- const EnumDecl *ed = cast<EnumType>(ty)->getDecl ();
466+ const EnumDecl *ed =
467+ cast<EnumType>(ty)->getOriginalDecl ()->getDefinitionOrSelf ();
461468 if (auto integerType = ed->getIntegerType (); !integerType.isNull ())
462469 return convertType (integerType);
463470 // Return a placeholder 'i32' type. This can be changed later when the
@@ -516,7 +523,7 @@ mlir::Type CIRGenTypes::convertTypeForMem(clang::QualType qualType,
516523// / Return record layout info for the given record decl.
517524const CIRGenRecordLayout &
518525CIRGenTypes::getCIRGenRecordLayout (const RecordDecl *rd) {
519- const auto *key = astContext.getTagDeclType (rd).getTypePtr ();
526+ const auto *key = astContext.getCanonicalTagType (rd).getTypePtr ();
520527
521528 // If we have already computed the layout, return it.
522529 auto it = cirGenRecordLayouts.find (key);
@@ -548,7 +555,7 @@ bool CIRGenTypes::isZeroInitializable(clang::QualType t) {
548555 }
549556
550557 if (const RecordType *rt = t->getAs <RecordType>()) {
551- const RecordDecl *rd = rt->getDecl ();
558+ const RecordDecl *rd = rt->getOriginalDecl ()-> getDefinitionOrSelf ();
552559 return isZeroInitializable (rd);
553560 }
554561
@@ -623,8 +630,10 @@ void CIRGenTypes::updateCompletedType(const TagDecl *td) {
623630 // declaration of enums, and C doesn't allow an incomplete forward
624631 // declaration with a non-default type.
625632 assert (
626- !typeCache.count (ed->getTypeForDecl ()) ||
627- (convertType (ed->getIntegerType ()) == typeCache[ed->getTypeForDecl ()]));
633+ !typeCache.count (
634+ ed->getASTContext ().getCanonicalTagType (ed)->getTypePtr ()) ||
635+ (convertType (ed->getIntegerType ()) ==
636+ typeCache[ed->getASTContext ().getCanonicalTagType (ed)->getTypePtr ()]));
628637 // If necessary, provide the full definition of a type only used with a
629638 // declaration so far.
630639 assert (!cir::MissingFeatures::generateDebugInfo ());
@@ -639,7 +648,7 @@ void CIRGenTypes::updateCompletedType(const TagDecl *td) {
639648
640649 // Only complete if we converted it already. If we haven't converted it yet,
641650 // we'll just do it lazily.
642- if (recordDeclTypes.count (astContext.getTagDeclType (rd).getTypePtr ()))
651+ if (recordDeclTypes.count (astContext.getCanonicalTagType (rd).getTypePtr ()))
643652 convertRecordDeclType (rd);
644653
645654 // If necessary, provide the full definition of a type only used with a
0 commit comments