From: David Majnemer Date: Fri, 1 Jul 2016 23:12:54 +0000 (+0000) Subject: [CodeView] Include MSVC style names for unnamed types X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=425312c448220a600bbb5186094f363d90c8b85a;p=clang [CodeView] Include MSVC style names for unnamed types The CodeView printer expects to be able to generate fully qualified names from the debug info graph. This means that we need to include the MSVC-style name in the debug info for anonymous types. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@274401 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 13461980a4..d51e1d978b 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -259,20 +259,56 @@ StringRef CGDebugInfo::getSelectorName(Selector S) { } StringRef CGDebugInfo::getClassName(const RecordDecl *RD) { - // quick optimization to avoid having to intern strings that are already - // stored reliably elsewhere - if (!isa(RD)) - return RD->getName(); - - SmallString<128> Name; - { + if (isa(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("" + +typedef struct { +} *test3; +test3 gv3; +void *use_test3 = &gv3; + +// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: ""