aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/MCDwarf.cpp
diff options
context:
space:
mode:
authorIgor Kudrin <ikudrin@accesssoftek.com>2022-01-21 13:04:32 +0700
committerIgor Kudrin <ikudrin@accesssoftek.com>2022-01-21 13:52:10 +0700
commit75184f14aecd8147a02189a843789a4eb5e5b571 (patch)
treef4cb95d50118523bf271008d24b8b699ac519469 /llvm/lib/MC/MCDwarf.cpp
parent8def89b5dc82efba039cca4ff9d072e169da7329 (diff)
downloadllvm-75184f14aecd8147a02189a843789a4eb5e5b571.zip
llvm-75184f14aecd8147a02189a843789a4eb5e5b571.tar.gz
llvm-75184f14aecd8147a02189a843789a4eb5e5b571.tar.bz2
[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
Diffstat (limited to 'llvm/lib/MC/MCDwarf.cpp')
-rw-r--r--llvm/lib/MC/MCDwarf.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/llvm/lib/MC/MCDwarf.cpp b/llvm/lib/MC/MCDwarf.cpp
index 1c9cfb9..15cfdba 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;
}