Skip to content

Commit 84b4603

Browse files
authored
[CIR][NFC] Simplify struct type name creation (#1556)
During review of a patch for upstreaming the cir.struct type support, Erich Keane observed that the code we use for creating our type name for structures with templates was likely to be error prone. He recommended using QualType::print with the appropriate printing policy instead. This change does that. Erich also pointed out that RecordDecls always have a DeclContext so a few other lines could be eliminated where that was checked.
1 parent 61259b3 commit 84b4603

File tree

1 file changed

+5
-22
lines changed

1 file changed

+5
-22
lines changed

clang/lib/CIR/CodeGen/CIRGenTypes.cpp

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -61,31 +61,14 @@ std::string CIRGenTypes::getRecordTypeName(const clang::RecordDecl *recordDecl,
6161

6262
PrintingPolicy policy = recordDecl->getASTContext().getPrintingPolicy();
6363
policy.SuppressInlineNamespace = false;
64+
policy.AlwaysIncludeTypeForTemplateArgument = true;
65+
policy.PrintCanonicalTypes = true;
66+
policy.SuppressTagKeyword = true;
6467

6568
if (recordDecl->getIdentifier()) {
66-
if (recordDecl->getDeclContext())
67-
recordDecl->printQualifiedName(outStream, policy);
68-
else
69-
recordDecl->printName(outStream, policy);
70-
71-
// Ensure each template specialization has a unique name.
72-
if (auto *templateSpecialization =
73-
llvm::dyn_cast<ClassTemplateSpecializationDecl>(recordDecl)) {
74-
outStream << '<';
75-
const auto args = templateSpecialization->getTemplateArgs().asArray();
76-
const auto printer = [&policy, &outStream](const TemplateArgument &arg) {
77-
/// Print this template argument to the given output stream.
78-
arg.print(policy, outStream, /*IncludeType=*/true);
79-
};
80-
llvm::interleaveComma(args, outStream, printer);
81-
outStream << '>';
82-
}
83-
69+
astContext.getRecordType(recordDecl).print(outStream, policy);
8470
} else if (auto *typedefNameDecl = recordDecl->getTypedefNameForAnonDecl()) {
85-
if (typedefNameDecl->getDeclContext())
86-
typedefNameDecl->printQualifiedName(outStream, policy);
87-
else
88-
typedefNameDecl->printName(outStream);
71+
typedefNameDecl->printQualifiedName(outStream, policy);
8972
} else {
9073
outStream << Builder.getUniqueAnonRecordName();
9174
}

0 commit comments

Comments
 (0)