[llvm] r274399 - [CodeView] Pretty print anonymous scopes

David Majnemer via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 1 16:12:45 PDT 2016


Author: majnemer
Date: Fri Jul  1 18:12:45 2016
New Revision: 274399

URL: http://llvm.org/viewvc/llvm-project?rev=274399&view=rev
Log:
[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
<unnamed-tag>.

Modified:
    llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
    llvm/trunk/test/DebugInfo/COFF/bitfields.ll
    llvm/trunk/test/DebugInfo/COFF/udts.ll

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp?rev=274399&r1=274398&r2=274399&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp Fri Jul  1 18:12:45 2016
@@ -128,13 +128,31 @@ CodeViewDebug::getInlineSite(const DILoc
   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 "<unnamed-tag>";
+  case dwarf::DW_TAG_namespace:
+    return "`anonymous namespace'";
+  }
+
+  return StringRef();
+}
+
 static const DISubprogram *getQualifiedNameComponents(
     const DIScope *Scope, SmallVectorImpl<StringRef> &QualifiedNameComponents) {
   const DISubprogram *ClosestSubprogram = nullptr;
   while (Scope != nullptr) {
     if (ClosestSubprogram == nullptr)
       ClosestSubprogram = dyn_cast<DISubprogram>(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<DIFile>(Scope))
@@ -184,8 +207,7 @@ TypeIndex CodeViewDebug::getScopeIndex(c
     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 DITy
       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(c
     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(
   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::lowerCompleteTy
   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::lowerCompleteTy
 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::lowerCompleteTy
   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,

Modified: llvm/trunk/test/DebugInfo/COFF/bitfields.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/COFF/bitfields.ll?rev=274399&r1=274398&r2=274399&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/COFF/bitfields.ll (original)
+++ llvm/trunk/test/DebugInfo/COFF/bitfields.ll Fri Jul  1 18:12:45 2016
@@ -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::<unnamed-tag>
+; 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::<unnamed-tag> ([[anon_ty]])
 ; CHECK:      FieldOffset: 0xB
 ; CHECK:      Name: v
 ; CHECK:    }
@@ -134,7 +145,7 @@
 ; CHECK:    ]
 ; CHECK:    FieldList: <field list> ([[anon_fl]])
 ; CHECK:    SizeOf: 3
-; CHECK:    Name: S1::
+; CHECK:    Name: S1::<unnamed-tag>
 ; CHECK:  }
 ; CHECK:  BitField ([[S2_y:.*]]) {
 ; CHECK:    TypeLeafKind: LF_BITFIELD (0x1205)

Modified: llvm/trunk/test/DebugInfo/COFF/udts.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/COFF/udts.ll?rev=274399&r1=274398&r2=274399&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/COFF/udts.ll (original)
+++ llvm/trunk/test/DebugInfo/COFF/udts.ll Fri Jul  1 18:12:45 2016
@@ -46,7 +46,7 @@ target triple = "i686-pc-windows-msvc18.
 ; CHECK-NEXT: Type: S (0x{{[0-9A-F]+}})
 ; CHECK-NEXT: UDTName: S
 ; CHECK:      UDT {
-; CHECK-NEXT: Type: 0x{{[0-9A-F]+}}
+; CHECK-NEXT: Type: <unnamed-tag> (0x{{[0-9A-F]+}})
 ; CHECK-NEXT: UDTName: U
 ; CHECK-NOT: UDT {
 




More information about the llvm-commits mailing list