@@ -95,28 +95,16 @@ std::string CIRGenTypes::getRecordTypeName(const clang::RecordDecl *recordDecl,
9595
9696 PrintingPolicy policy = recordDecl->getASTContext ().getPrintingPolicy ();
9797 policy.SuppressInlineNamespace = false ;
98+ policy.AlwaysIncludeTypeForTemplateArgument = true ;
99+ policy.PrintCanonicalTypes = true ;
100+ policy.SuppressTagKeyword = true ;
98101
99- if (recordDecl->getIdentifier ()) {
100- recordDecl->printQualifiedName (outStream, policy);
101-
102- // Ensure each template specialization has a unique name.
103- if (auto *templateSpecialization =
104- llvm::dyn_cast<ClassTemplateSpecializationDecl>(recordDecl)) {
105- outStream << ' <' ;
106- const ArrayRef<TemplateArgument> args =
107- templateSpecialization->getTemplateArgs ().asArray ();
108- const auto printer = [&policy, &outStream](const TemplateArgument &arg) {
109- // / Print this template argument to the given output stream.
110- arg.print (policy, outStream, /* IncludeType=*/ true );
111- };
112- llvm::interleaveComma (args, outStream, printer);
113- outStream << ' >' ;
114- }
115- } else if (auto *typedefNameDecl = recordDecl->getTypedefNameForAnonDecl ()) {
102+ if (recordDecl->getIdentifier ())
103+ astContext.getRecordType (recordDecl).print (outStream, policy);
104+ else if (auto *typedefNameDecl = recordDecl->getTypedefNameForAnonDecl ())
116105 typedefNameDecl->printQualifiedName (outStream, policy);
117- } else {
106+ else
118107 outStream << builder.getUniqueAnonRecordName ();
119- }
120108
121109 if (!suffix.empty ())
122110 outStream << suffix;
@@ -131,7 +119,9 @@ mlir::Type CIRGenTypes::convertRecordDeclType(const clang::RecordDecl *rd) {
131119 const Type *key = astContext.getTagDeclType (rd).getTypePtr ();
132120 cir::StructType entry = recordDeclTypes[key];
133121
134- // Handle forward decl / incomplete types.
122+ // If we don't have an entry for this record yet, create one.
123+ // We create an incomplete type initially. If `rd` is complete, we will
124+ // add the members below.
135125 if (!entry) {
136126 auto name = getRecordTypeName (rd, " " );
137127 entry = builder.getIncompleteStructTy (name, rd);
0 commit comments