diff options
author | Adrian Prantl <aprantl@apple.com> | 2018-12-06 18:44:48 +0000 |
---|---|---|
committer | Adrian Prantl <aprantl@apple.com> | 2018-12-06 18:44:48 +0000 |
commit | fbeeac0e1e96ae36f65bb17424ef0fe00a95d8ed (patch) | |
tree | 94bc90c6c14045a3f1b8fa6e4194f395f01a11aa /llvm/lib/Transforms | |
parent | df0c7ec011f2e1992f6d510c79f580fdf74ba1e6 (diff) | |
download | bcm5719-llvm-fbeeac0e1e96ae36f65bb17424ef0fe00a95d8ed.tar.gz bcm5719-llvm-fbeeac0e1e96ae36f65bb17424ef0fe00a95d8ed.zip |
Reapply "Adapt gcov to changes in CFE."
This reverts commit r348203 and reapplies D55085 with an additional
GCOV bugfix to make the change NFC for relative file paths in .gcno files.
Thanks to Ilya Biryukov for additional testing!
Original commit message:
Update Diagnostic handling for changes in CFE.
The clang frontend no longer emits the current working directory for
DIFiles containing an absolute path in the filename: and will move the
common prefix between current working directory and the file into the
directory: component.
https://reviews.llvm.org/D55085
llvm-svn: 348512
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp index e580503a912..829123911c6 100644 --- a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp +++ b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp @@ -180,6 +180,21 @@ static StringRef getFunctionName(const DISubprogram *SP) { return SP->getName(); } +/// Extract a filename for a DISubprogram. +/// +/// Prefer relative paths in the coverage notes. Clang also may split +/// up absolute paths into a directory and filename component. When +/// the relative path doesn't exist, reconstruct the absolute path. +SmallString<128> getFilename(const DISubprogram *SP) { + SmallString<128> Path; + StringRef RelPath = SP->getFilename(); + if (sys::fs::exists(RelPath)) + Path = RelPath; + else + sys::path::append(Path, SP->getDirectory(), SP->getFilename()); + return Path; +} + namespace { class GCOVRecord { protected: @@ -256,7 +271,7 @@ namespace { } private: - StringRef Filename; + std::string Filename; SmallVector<uint32_t, 32> Lines; }; @@ -377,8 +392,9 @@ namespace { void writeOut() { writeBytes(FunctionTag, 4); + SmallString<128> Filename = getFilename(SP); uint32_t BlockLen = 1 + 1 + 1 + lengthOfGCOVString(getFunctionName(SP)) + - 1 + lengthOfGCOVString(SP->getFilename()) + 1; + 1 + lengthOfGCOVString(Filename) + 1; if (UseCfgChecksum) ++BlockLen; write(BlockLen); @@ -387,7 +403,7 @@ namespace { if (UseCfgChecksum) write(CfgChecksum); writeGCOVString(getFunctionName(SP)); - writeGCOVString(SP->getFilename()); + writeGCOVString(Filename); write(SP->getLine()); // Emit count of blocks. @@ -466,7 +482,7 @@ bool GCOVProfiler::isFunctionInstrumented(const Function &F) { if (FilterRe.empty() && ExcludeRe.empty()) { return true; } - const StringRef Filename = F.getSubprogram()->getFilename(); + SmallString<128> Filename = getFilename(F.getSubprogram()); auto It = InstrumentedFiles.find(Filename); if (It != InstrumentedFiles.end()) { return It->second; @@ -688,7 +704,8 @@ void GCOVProfiler::emitProfileNotes() { // Add the function line number to the lines of the entry block // to have a counter for the function definition. uint32_t Line = SP->getLine(); - Func.getBlock(&EntryBlock).getFile(SP->getFilename()).addLine(Line); + auto Filename = getFilename(SP); + Func.getBlock(&EntryBlock).getFile(Filename).addLine(Line); for (auto &BB : F) { GCOVBlock &Block = Func.getBlock(&BB); @@ -719,7 +736,7 @@ void GCOVProfiler::emitProfileNotes() { if (SP != getDISubprogram(Loc.getScope())) continue; - GCOVLines &Lines = Block.getFile(SP->getFilename()); + GCOVLines &Lines = Block.getFile(Filename); Lines.addLine(Loc.getLine()); } Line = 0; |