}
StringRef CGDebugInfo::getClassName(const RecordDecl *RD) {
- // quick optimization to avoid having to intern strings that are already
- // stored reliably elsewhere
- if (!isa<ClassTemplateSpecializationDecl>(RD))
- return RD->getName();
-
- SmallString<128> Name;
- {
+ if (isa<ClassTemplateSpecializationDecl>(RD)) {
+ SmallString<128> Name;
llvm::raw_svector_ostream OS(Name);
RD->getNameForDiagnostic(OS, CGM.getContext().getPrintingPolicy(),
/*Qualified*/ false);
+
+ // Copy this name on the side and use its reference.
+ return internString(Name);
}
- // Copy this name on the side and use its reference.
- return internString(Name);
+ // quick optimization to avoid having to intern strings that are already
+ // stored reliably elsewhere
+ if (const IdentifierInfo *II = RD->getIdentifier())
+ return II->getName();
+
+ // The CodeView printer in LLVM wants to see the names of unnamed types: it is
+ // used to reconstruct the fully qualified type names.
+ if (CGM.getCodeGenOpts().EmitCodeView) {
+ if (const TypedefNameDecl *D = RD->getTypedefNameForAnonDecl()) {
+ assert(RD->getDeclContext() == D->getDeclContext() &&
+ "Typedef should not be in another decl context!");
+ assert(D->getDeclName().getAsIdentifierInfo() &&
+ "Typedef was not named!");
+ return D->getDeclName().getAsIdentifierInfo()->getName();
+ }
+
+ if (CGM.getLangOpts().CPlusPlus) {
+ StringRef Name;
+
+ ASTContext &Context = CGM.getContext();
+ if (const DeclaratorDecl *DD = Context.getDeclaratorForUnnamedTagDecl(RD))
+ // Anonymous types without a name for linkage purposes have their
+ // declarator mangled in if they have one.
+ Name = DD->getName();
+ else if (const TypedefNameDecl *TND =
+ Context.getTypedefNameForUnnamedTagDecl(RD))
+ // Anonymous types without a name for linkage purposes have their
+ // associate typedef mangled in if they have one.
+ Name = TND->getName();
+
+ if (!Name.empty()) {
+ SmallString<256> UnnamedType("<unnamed-type-");
+ UnnamedType += Name;
+ UnnamedType += '>';
+ return internString(UnnamedType);
+ }
+ }
+ }
+
+ return StringRef();
}
llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
--- /dev/null
+// RUN: %clang_cc1 -triple x86_64-pc-win32 -debug-info-kind=limited -gcodeview %s -emit-llvm -o - | FileCheck %s
+
+typedef struct {
+} test1;
+
+test1 gv1;
+// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "test1"
+
+struct {
+} test2;
+void *use_test2 = &test2;
+
+// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "<unnamed-type-test2>"
+
+typedef struct {
+} *test3;
+test3 gv3;
+void *use_test3 = &gv3;
+
+// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "<unnamed-type-test3>"