From 0c69559ee3729df7bf359e12a067b161ce4dbe91 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Fri, 1 Jul 2016 23:12:45 +0000 Subject: [PATCH] [CodeView] Pretty print anonymous scopes A namespace without a name should be written out as `anonymous namespace' while a tag type without a name should be written out as . git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274399 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/AsmPrinter/CodeViewDebug.cpp | 45 ++++++++++++++++-------- test/DebugInfo/COFF/bitfields.ll | 13 ++++++- test/DebugInfo/COFF/udts.ll | 2 +- 3 files changed, 44 insertions(+), 16 deletions(-) diff --git a/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp index d567d6a87cb..b847219b2fd 100644 --- a/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp +++ b/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp @@ -128,13 +128,31 @@ CodeViewDebug::getInlineSite(const DILocation *InlinedAt, return *Site; } +static StringRef getPrettyScopeName(const DIScope *Scope) { + StringRef ScopeName = Scope->getName(); + if (!ScopeName.empty()) + return ScopeName; + + switch (Scope->getTag()) { + case dwarf::DW_TAG_enumeration_type: + case dwarf::DW_TAG_class_type: + case dwarf::DW_TAG_structure_type: + case dwarf::DW_TAG_union_type: + return ""; + case dwarf::DW_TAG_namespace: + return "`anonymous namespace'"; + } + + return StringRef(); +} + static const DISubprogram *getQualifiedNameComponents( const DIScope *Scope, SmallVectorImpl &QualifiedNameComponents) { const DISubprogram *ClosestSubprogram = nullptr; while (Scope != nullptr) { if (ClosestSubprogram == nullptr) ClosestSubprogram = dyn_cast(Scope); - StringRef ScopeName = Scope->getName(); + StringRef ScopeName = getPrettyScopeName(Scope); if (!ScopeName.empty()) QualifiedNameComponents.push_back(ScopeName); Scope = Scope->getScope().resolve(); @@ -171,6 +189,11 @@ struct CodeViewDebug::TypeLoweringScope { CodeViewDebug &CVD; }; +static std::string getFullyQualifiedName(const DIScope *Ty) { + const DIScope *Scope = Ty->getScope().resolve(); + return getFullyQualifiedName(Scope, getPrettyScopeName(Ty)); +} + TypeIndex CodeViewDebug::getScopeIndex(const DIScope *Scope) { // No scope means global scope and that uses the zero index. if (!Scope || isa(Scope)) @@ -184,8 +207,7 @@ TypeIndex CodeViewDebug::getScopeIndex(const DIScope *Scope) { return I->second; // Build the fully qualified name of the scope. - std::string ScopeName = - getFullyQualifiedName(Scope->getScope().resolve(), Scope->getName()); + std::string ScopeName = getFullyQualifiedName(Scope); TypeIndex TI = TypeTable.writeStringId(StringIdRecord(TypeIndex(), ScopeName)); return recordTypeIndexForDINode(Scope, TI); @@ -882,7 +904,7 @@ void CodeViewDebug::addToUDTs(const DIType *Ty, TypeIndex TI) { Ty->getScope().resolve(), QualifiedNameComponents); std::string FullyQualifiedName = - getQualifiedName(QualifiedNameComponents, Ty->getName()); + getQualifiedName(QualifiedNameComponents, getPrettyScopeName(Ty)); if (ClosestSubprogram == nullptr) GlobalUDTs.emplace_back(std::move(FullyQualifiedName), TI); @@ -1342,8 +1364,7 @@ TypeIndex CodeViewDebug::lowerTypeEnum(const DICompositeType *Ty) { FTI = TypeTable.writeFieldList(Fields); } - std::string FullName = - getFullyQualifiedName(Ty->getScope().resolve(), Ty->getName()); + std::string FullName = getFullyQualifiedName(Ty); return TypeTable.writeEnum(EnumRecord(EnumeratorCount, CO, FTI, FullName, Ty->getIdentifier(), @@ -1439,8 +1460,7 @@ TypeIndex CodeViewDebug::lowerTypeClass(const DICompositeType *Ty) { TypeRecordKind Kind = getRecordKind(Ty); ClassOptions CO = ClassOptions::ForwardReference | getRecordUniqueNameOption(Ty); - std::string FullName = - getFullyQualifiedName(Ty->getScope().resolve(), Ty->getName()); + std::string FullName = getFullyQualifiedName(Ty); TypeIndex FwdDeclTI = TypeTable.writeClass(ClassRecord( Kind, 0, CO, HfaKind::None, WindowsRTClassKind::None, TypeIndex(), TypeIndex(), TypeIndex(), 0, FullName, Ty->getIdentifier())); @@ -1459,8 +1479,7 @@ TypeIndex CodeViewDebug::lowerCompleteTypeClass(const DICompositeType *Ty) { unsigned FieldCount; std::tie(FieldTI, VShapeTI, FieldCount) = lowerRecordFieldList(Ty); - std::string FullName = - getFullyQualifiedName(Ty->getScope().resolve(), Ty->getName()); + std::string FullName = getFullyQualifiedName(Ty); uint64_t SizeInBytes = Ty->getSizeInBits() / 8; @@ -1481,8 +1500,7 @@ TypeIndex CodeViewDebug::lowerCompleteTypeClass(const DICompositeType *Ty) { TypeIndex CodeViewDebug::lowerTypeUnion(const DICompositeType *Ty) { ClassOptions CO = ClassOptions::ForwardReference | getRecordUniqueNameOption(Ty); - std::string FullName = - getFullyQualifiedName(Ty->getScope().resolve(), Ty->getName()); + std::string FullName = getFullyQualifiedName(Ty); TypeIndex FwdDeclTI = TypeTable.writeUnion(UnionRecord(0, CO, HfaKind::None, TypeIndex(), 0, FullName, Ty->getIdentifier())); @@ -1497,8 +1515,7 @@ TypeIndex CodeViewDebug::lowerCompleteTypeUnion(const DICompositeType *Ty) { unsigned FieldCount; std::tie(FieldTI, std::ignore, FieldCount) = lowerRecordFieldList(Ty); uint64_t SizeInBytes = Ty->getSizeInBits() / 8; - std::string FullName = - getFullyQualifiedName(Ty->getScope().resolve(), Ty->getName()); + std::string FullName = getFullyQualifiedName(Ty); TypeIndex UnionTI = TypeTable.writeUnion( UnionRecord(FieldCount, CO, HfaKind::None, FieldTI, SizeInBytes, FullName, diff --git a/test/DebugInfo/COFF/bitfields.ll b/test/DebugInfo/COFF/bitfields.ll index b6fe2b3d706..46f006674ac 100644 --- a/test/DebugInfo/COFF/bitfields.ll +++ b/test/DebugInfo/COFF/bitfields.ll @@ -63,6 +63,16 @@ ; CHECK: BitSize: 2 ; CHECK: BitOffset: 23 ; CHECK: } +; CHECK: Struct ([[anon_ty:.*]]) { +; CHECK: TypeLeafKind: LF_STRUCTURE (0x1505) +; CHECK: MemberCount: 0 +; CHECK: Properties [ (0x80) +; CHECK: ForwardReference (0x80) +; CHECK: ] +; CHECK: FieldList: 0x0 +; CHECK: SizeOf: 0 +; CHECK: Name: S1:: +; CHECK: } ; CHECK: BitField ([[S1_u:.*]]) { ; CHECK: TypeLeafKind: LF_BITFIELD (0x1205) ; CHECK: Type: short (0x11) @@ -96,6 +106,7 @@ ; CHECK: Name: w ; CHECK: } ; CHECK: DataMember { +; CHECK: Type: S1:: ([[anon_ty]]) ; CHECK: FieldOffset: 0xB ; CHECK: Name: v ; CHECK: } @@ -134,7 +145,7 @@ ; CHECK: ] ; CHECK: FieldList: ([[anon_fl]]) ; CHECK: SizeOf: 3 -; CHECK: Name: S1:: +; CHECK: Name: S1:: ; CHECK: } ; CHECK: BitField ([[S2_y:.*]]) { ; CHECK: TypeLeafKind: LF_BITFIELD (0x1205) diff --git a/test/DebugInfo/COFF/udts.ll b/test/DebugInfo/COFF/udts.ll index b772e9c3641..bb0686f313f 100644 --- a/test/DebugInfo/COFF/udts.ll +++ b/test/DebugInfo/COFF/udts.ll @@ -46,7 +46,7 @@ target triple = "i686-pc-windows-msvc18.0.0" ; CHECK-NEXT: Type: S (0x{{[0-9A-F]+}}) ; CHECK-NEXT: UDTName: S ; CHECK: UDT { -; CHECK-NEXT: Type: 0x{{[0-9A-F]+}} +; CHECK-NEXT: Type: (0x{{[0-9A-F]+}}) ; CHECK-NEXT: UDTName: U ; CHECK-NOT: UDT { -- 2.49.0