diff options
author | David Majnemer <david.majnemer@gmail.com> | 2016-07-01 23:12:54 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2016-07-01 23:12:54 +0000 |
commit | bc5976ad582efd402f4e2dc614f30110ab1f7009 (patch) | |
tree | 26e62e449397f766d58077c4010c1c8021133472 /clang | |
parent | 08bd744c2c13b5b13d7c370110ad7b77b2c98e73 (diff) | |
download | bcm5719-llvm-bc5976ad582efd402f4e2dc614f30110ab1f7009.tar.gz bcm5719-llvm-bc5976ad582efd402f4e2dc614f30110ab1f7009.zip |
[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.
llvm-svn: 274401
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/CodeGen/CGDebugInfo.cpp | 54 | ||||
-rw-r--r-- | clang/test/CodeGenCXX/debug-info-ms-anonymous-tag.cpp | 20 |
2 files changed, 65 insertions, 9 deletions
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 13461980a4b..d51e1d978bb 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/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<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) { diff --git a/clang/test/CodeGenCXX/debug-info-ms-anonymous-tag.cpp b/clang/test/CodeGenCXX/debug-info-ms-anonymous-tag.cpp new file mode 100644 index 00000000000..cef1eb8c5a0 --- /dev/null +++ b/clang/test/CodeGenCXX/debug-info-ms-anonymous-tag.cpp @@ -0,0 +1,20 @@ +// 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>" |