[llvm] r326824 - [CodeView] Emit UdtSourceLine information for enums

Aaron Smith via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 6 10:20:22 PST 2018


Author: asmith
Date: Tue Mar  6 10:20:22 2018
New Revision: 326824

URL: http://llvm.org/viewvc/llvm-project?rev=326824&view=rev
Log:
[CodeView] Emit UdtSourceLine information for enums

Summary:
- Emit UdtSourceLine information for enums to match MSVC

- Add a method to add UDTSrcLine and call it for all Class/Struct/Union/Enum

- Update test cases to verify the changes

Reviewers: zturner, llvm-commits, rnk

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D44116

Modified:
    llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h
    llvm/trunk/test/DebugInfo/COFF/enum.ll
    llvm/trunk/test/DebugInfo/COFF/nested-types.ll

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp?rev=326824&r1=326823&r2=326824&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp Tue Mar  6 10:20:22 2018
@@ -1769,6 +1769,26 @@ static ClassOptions getCommonClassOption
   return CO;
 }
 
+void CodeViewDebug::addUDTSrcLine(const DIType *Ty, TypeIndex TI) {
+  switch (Ty->getTag()) {
+  case dwarf::DW_TAG_class_type:
+  case dwarf::DW_TAG_structure_type:
+  case dwarf::DW_TAG_union_type:
+  case dwarf::DW_TAG_enumeration_type:
+    break;
+  default:
+    return;
+  }
+
+  if (const auto *File = Ty->getFile()) {
+    StringIdRecord SIDR(TypeIndex(0x0), getFullFilepath(File));
+    TypeIndex SIDI = TypeTable.writeLeafType(SIDR);
+
+    UdtSourceLineRecord USLR(TI, SIDI, Ty->getLine());
+    TypeTable.writeLeafType(USLR);
+  }
+}
+
 TypeIndex CodeViewDebug::lowerTypeEnum(const DICompositeType *Ty) {
   ClassOptions CO = getCommonClassOptions(Ty);
   TypeIndex FTI;
@@ -1797,7 +1817,11 @@ TypeIndex CodeViewDebug::lowerTypeEnum(c
 
   EnumRecord ER(EnumeratorCount, CO, FTI, FullName, Ty->getIdentifier(),
                 getTypeIndex(Ty->getBaseType()));
-  return TypeTable.writeLeafType(ER);
+  TypeIndex EnumTI = TypeTable.writeLeafType(ER);
+
+  addUDTSrcLine(Ty, EnumTI);
+
+  return EnumTI;
 }
 
 //===----------------------------------------------------------------------===//
@@ -1949,13 +1973,7 @@ TypeIndex CodeViewDebug::lowerCompleteTy
                  SizeInBytes, FullName, Ty->getIdentifier());
   TypeIndex ClassTI = TypeTable.writeLeafType(CR);
 
-  if (const auto *File = Ty->getFile()) {
-    StringIdRecord SIDR(TypeIndex(0x0), getFullFilepath(File));
-    TypeIndex SIDI = TypeTable.writeLeafType(SIDR);
-
-    UdtSourceLineRecord USLR(ClassTI, SIDI, Ty->getLine());
-    TypeTable.writeLeafType(USLR);
-  }
+  addUDTSrcLine(Ty, ClassTI);
 
   addToUDTs(Ty);
 
@@ -1991,11 +2009,7 @@ TypeIndex CodeViewDebug::lowerCompleteTy
                  Ty->getIdentifier());
   TypeIndex UnionTI = TypeTable.writeLeafType(UR);
 
-  StringIdRecord SIR(TypeIndex(0x0), getFullFilepath(Ty->getFile()));
-  TypeIndex SIRI = TypeTable.writeLeafType(SIR);
-
-  UdtSourceLineRecord USLR(UnionTI, SIRI, Ty->getLine());
-  TypeTable.writeLeafType(USLR);
+  addUDTSrcLine(Ty, UnionTI);
 
   addToUDTs(Ty);
 

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h?rev=326824&r1=326823&r2=326824&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h Tue Mar  6 10:20:22 2018
@@ -279,6 +279,8 @@ class LLVM_LIBRARY_VISIBILITY CodeViewDe
 
   void addToUDTs(const DIType *Ty);
 
+  void addUDTSrcLine(const DIType *Ty, codeview::TypeIndex TI);
+
   codeview::TypeIndex lowerType(const DIType *Ty, const DIType *ClassTy);
   codeview::TypeIndex lowerTypeAlias(const DIDerivedType *Ty);
   codeview::TypeIndex lowerTypeArray(const DICompositeType *Ty);

Modified: llvm/trunk/test/DebugInfo/COFF/enum.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/COFF/enum.ll?rev=326824&r1=326823&r2=326824&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/COFF/enum.ll (original)
+++ llvm/trunk/test/DebugInfo/COFF/enum.ll Tue Mar  6 10:20:22 2018
@@ -23,6 +23,17 @@
 ; CHECK-NEXT:    FieldListType: <field list> (0x1000)
 ; CHECK-NEXT:    Name: E
 ; CHECK-NEXT:  }
+; CHECK-NEXT:  StringId (0x1002) {
+; CHECK-NEXT:    TypeLeafKind: LF_STRING_ID (0x1605)
+; CHECK-NEXT:    Id: 0x0
+; CHECK-NEXT:    StringData: \<stdin>
+; CHECK-NEXT:  }
+; CHECK-NEXT:  UdtSourceLine (0x1003) {
+; CHECK-NEXT:    TypeLeafKind: LF_UDT_SRC_LINE (0x1606)
+; CHECK-NEXT:    UDT: E (0x1001)
+; CHECK-NEXT:    SourceFile: \<stdin> (0x1002)
+; CHECK-NEXT:    LineNumber: 1
+; CHECK_NEXT  }
 
 source_filename = "test/DebugInfo/COFF/enum.ll"
 target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"

Modified: llvm/trunk/test/DebugInfo/COFF/nested-types.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/COFF/nested-types.ll?rev=326824&r1=326823&r2=326824&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/COFF/nested-types.ll (original)
+++ llvm/trunk/test/DebugInfo/COFF/nested-types.ll Tue Mar  6 10:20:22 2018
@@ -134,7 +134,7 @@ target triple = "x86_64-pc-windows-msvc1
 ; CHECK-NEXT:   }
 ; CHECK-NEXT: }
 ;
-; CHECK:      Struct (0x1007) {
+; CHECK:      Struct (0x{{.*}}) {
 ; CHECK-NEXT:   TypeLeafKind: LF_STRUCTURE (0x1505)
 ; CHECK-NEXT:   MemberCount: 4
 ; CHECK-NEXT:   Properties [ (0x210)




More information about the llvm-commits mailing list