[llvm] 75184f1 - [DebugInfo] Fix handling '# line "file"' for DWARFv5

Igor Kudrin via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 20 22:52:53 PST 2022


Author: Igor Kudrin
Date: 2022-01-21T13:52:10+07:00
New Revision: 75184f14aecd8147a02189a843789a4eb5e5b571

URL: https://github.com/llvm/llvm-project/commit/75184f14aecd8147a02189a843789a4eb5e5b571
DIFF: https://github.com/llvm/llvm-project/commit/75184f14aecd8147a02189a843789a4eb5e5b571.diff

LOG: [DebugInfo] Fix handling '# line "file"' for DWARFv5

`CppHashInfo.Filename` is a `StringRef` that references a part of the
source file and it is not null-terminated at the end of the file name.
`AsmParser::parseAndMatchAndEmitTargetInstruction()` passes it to
`getStreamer().emitDwarfFileDirective()`, and it eventually comes to
`isRootFile()`. The comparison fails because `FileName.data()` is not
properly terminated.

In addition, the old code might cause a significant speed degradation
for long source files. The `operator!=()` for `std::string` and
`const char *` can be implemented in a way that it finds the length of
the second argument first, which slows the comparison for long data.
`parseAndMatchAndEmitTargetInstruction()` calls
`emitDwarfFileDirective()` every time if `CppHashInfo.Filename` is not
empty. As a result, the longer the source file is, the slower the
compilation wend, and for a very long file, it might take hours instead
of a couple of seconds normally.

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

Added: 
    

Modified: 
    llvm/lib/MC/MCDwarf.cpp
    llvm/test/MC/ELF/debug-hash-file.s

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/MCDwarf.cpp b/llvm/lib/MC/MCDwarf.cpp
index 1c9cfb9042e28..15cfdba5d7fde 100644
--- a/llvm/lib/MC/MCDwarf.cpp
+++ b/llvm/lib/MC/MCDwarf.cpp
@@ -561,7 +561,7 @@ Expected<unsigned> MCDwarfLineTable::tryGetFile(StringRef &Directory,
 
 static bool isRootFile(const MCDwarfFile &RootFile, StringRef &Directory,
                        StringRef &FileName, Optional<MD5::MD5Result> Checksum) {
-  if (RootFile.Name.empty() || RootFile.Name != FileName.data())
+  if (RootFile.Name.empty() || StringRef(RootFile.Name) != FileName)
     return false;
   return RootFile.Checksum == Checksum;
 }

diff  --git a/llvm/test/MC/ELF/debug-hash-file.s b/llvm/test/MC/ELF/debug-hash-file.s
index a72e5d6aa8d42..9d4cf6ae68bdc 100644
--- a/llvm/test/MC/ELF/debug-hash-file.s
+++ b/llvm/test/MC/ELF/debug-hash-file.s
@@ -1,5 +1,8 @@
 // RUN: llvm-mc -triple x86_64-unknown-linux-gnu -filetype obj -g -dwarf-version 4 -o %t %s
-// RUN: llvm-dwarfdump -debug-info -debug-line %t | FileCheck %s
+// RUN: llvm-dwarfdump -debug-info -debug-line %t | FileCheck %s --check-prefixes=CHECK,DWARF4
+
+// RUN: llvm-mc -triple x86_64-unknown-linux-gnu -filetype obj -g -dwarf-version 5 -o %t %s
+// RUN: llvm-dwarfdump -debug-info -debug-line %t | FileCheck %s --check-prefixes=CHECK,DWARF5
 
 // CHECK: DW_TAG_compile_unit
 // CHECK-NOT: DW_TAG_
@@ -8,10 +11,17 @@
 // CHECK-NOT: DW_TAG_
 // CHECK: DW_AT_decl_file ("/MyTest/Inputs{{(/|\\)+}}other.S")
 
-// CHECK: include_directories[ 1] = "/MyTest/Inputs"
-// CHECK: file_names[ 1]:
-// CHECK-NEXT: name: "other.S"
-// CHECK-NEXT: dir_index: 1
+// DWARF4: include_directories[ 1] = "/MyTest/Inputs"
+// DWARF4: file_names[ 1]:
+// DWARF4-NEXT: name: "other.S"
+// DWARF4-NEXT: dir_index: 1
+
+// DWARF5:      include_directories[ 0] =
+// DWARF5-NOT:  include_directories[ 1] =
+// DWARF5:      file_names[ 0]:
+// DWARF5-NEXT:           name: "/MyTest/Inputs/other.S"
+// DWARF5-NEXT:      dir_index: 0
+// DWARF5-NOT:  file_names[ 1]:
 
 # 1 "/MyTest/Inputs/other.S"
 


        


More information about the llvm-commits mailing list