Skip to content

Commit e51dfab

Browse files
andykaylorlanza
authored andcommitted
[CIR][NFC] Simplify struct type name creation (llvm#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 4642640 commit e51dfab

File tree

1 file changed

+4
-22
lines changed

1 file changed

+4
-22
lines changed

clang/lib/CIR/CodeGen/CIRGenTypes.cpp

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -61,31 +61,13 @@ 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.SuppressTagKeyword = true;
6466

6567
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-
68+
astContext.getRecordType(recordDecl).print(outStream, policy);
8469
} else if (auto *typedefNameDecl = recordDecl->getTypedefNameForAnonDecl()) {
85-
if (typedefNameDecl->getDeclContext())
86-
typedefNameDecl->printQualifiedName(outStream, policy);
87-
else
88-
typedefNameDecl->printName(outStream);
70+
typedefNameDecl->printQualifiedName(outStream, policy);
8971
} else {
9072
outStream << Builder.getUniqueAnonRecordName();
9173
}

0 commit comments

Comments
 (0)