[llvm] r335350 - [DWARFv5] Allow ".loc 0" to refer to the root file.

Paul Robinson via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 22 07:16:11 PDT 2018


Author: probinson
Date: Fri Jun 22 07:16:11 2018
New Revision: 335350

URL: http://llvm.org/viewvc/llvm-project?rev=335350&view=rev
Log:
[DWARFv5] Allow ".loc 0" to refer to the root file.

DWARF v5 explicitly represents file #0 in the line table.  Prior
versions did not, so ".loc 0" is still an error in those cases.

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

Added:
    llvm/trunk/test/MC/ELF/dwarf-loc0.s
Modified:
    llvm/trunk/include/llvm/MC/MCDwarf.h
    llvm/trunk/lib/MC/MCContext.cpp
    llvm/trunk/lib/MC/MCParser/AsmParser.cpp

Modified: llvm/trunk/include/llvm/MC/MCDwarf.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCDwarf.h?rev=335350&r1=335349&r2=335350&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCDwarf.h (original)
+++ llvm/trunk/include/llvm/MC/MCDwarf.h Fri Jun 22 07:16:11 2018
@@ -314,10 +314,13 @@ public:
 
   void resetRootFile() {
     assert(Header.MCDwarfFiles.empty());
+    Header.RootFile.Name.clear();
     Header.resetMD5Usage();
     Header.HasSource = false;
   }
 
+  bool hasRootFile() const { return !Header.RootFile.Name.empty(); }
+
   // Report whether MD5 usage has been consistent (all-or-none).
   bool isMD5UsageConsistent() const { return Header.isMD5UsageConsistent(); }
 

Modified: llvm/trunk/lib/MC/MCContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCContext.cpp?rev=335350&r1=335349&r2=335350&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCContext.cpp (original)
+++ llvm/trunk/lib/MC/MCContext.cpp Fri Jun 22 07:16:11 2018
@@ -556,11 +556,13 @@ Expected<unsigned> MCContext::getDwarfFi
 /// isValidDwarfFileNumber - takes a dwarf file number and returns true if it
 /// currently is assigned and false otherwise.
 bool MCContext::isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID) {
-  const SmallVectorImpl<MCDwarfFile> &MCDwarfFiles = getMCDwarfFiles(CUID);
-  if (FileNumber == 0 || FileNumber >= MCDwarfFiles.size())
+  const MCDwarfLineTable &LineTable = getMCDwarfLineTable(CUID);
+  if (FileNumber == 0)
+    return getDwarfVersion() >= 5 && LineTable.hasRootFile();
+  if (FileNumber >= LineTable.getMCDwarfFiles().size())
     return false;
 
-  return !MCDwarfFiles[FileNumber].Name.empty();
+  return !LineTable.getMCDwarfFiles()[FileNumber].Name.empty();
 }
 
 /// Remove empty sections from SectionStartEndSyms, to avoid generating

Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=335350&r1=335349&r2=335350&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Fri Jun 22 07:16:11 2018
@@ -3412,7 +3412,7 @@ bool AsmParser::parseDirectiveLoc() {
   int64_t FileNumber = 0, LineNumber = 0;
   SMLoc Loc = getTok().getLoc();
   if (parseIntToken(FileNumber, "unexpected token in '.loc' directive") ||
-      check(FileNumber < 1, Loc,
+      check(FileNumber < 1 && Ctx.getDwarfVersion() < 5, Loc,
             "file number less than one in '.loc' directive") ||
       check(!getContext().isValidDwarfFileNumber(FileNumber), Loc,
             "unassigned file number in '.loc' directive"))

Added: llvm/trunk/test/MC/ELF/dwarf-loc0.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/dwarf-loc0.s?rev=335350&view=auto
==============================================================================
--- llvm/trunk/test/MC/ELF/dwarf-loc0.s (added)
+++ llvm/trunk/test/MC/ELF/dwarf-loc0.s Fri Jun 22 07:16:11 2018
@@ -0,0 +1,26 @@
+# RUN: llvm-mc -dwarf-version 5 %s -filetype=obj -o - | llvm-dwarfdump -debug-line - | FileCheck %s
+# RUN: not llvm-mc -dwarf-version 4 %s -filetype=asm -o - 2>&1 | FileCheck %s -check-prefix=ERR
+# REQUIRES: default_triple
+# Darwin line table is stuck on DWARF v2.
+# XFAIL: darwin
+# Show that ".loc 0" works in DWARF v5, gets an error for earlier versions.
+        .file 0 "root.cpp"
+        .file 1 "header.h"
+	.loc  0 10 0
+        nop
+        .loc  1 20 0
+        nop
+
+# CHECK:      file_names[ 0]:
+# CHECK-NEXT: name: "root.cpp"
+# CHECK:      file_names[ 1]:
+# CHECK-NEXT: name: "header.h"
+# CHECK:      Address Line Column File
+# CHECK-NEXT: -------
+# CHECK-NEXT: 0x{{0+}}0 10 0 0
+# CHECK-NEXT: 0x{{0+}}1 20 0 1
+# CHECK-NEXT: 0x{{0+}}2 20 0 1 {{.*}} end_sequence
+
+# ERR:      file number less than one in '.loc' directive
+# ERR-NEXT: .loc 0 10 0
+# ERR-NEXT: ^




More information about the llvm-commits mailing list