diff options
author | Bill Wendling <isanbard@gmail.com> | 2012-08-29 20:30:44 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2012-08-29 20:30:44 +0000 |
commit | 0e76db9ad43383ca9aeff7001a98d6d6d8d5e736 (patch) | |
tree | a98d3ccf0993731cc5f1ae9266f8de3ddd1c013a /lib/Transforms/Instrumentation/GCOVProfiling.cpp | |
parent | bbd169b1d96e1012df9852d41b7fd00381ed9d48 (diff) |
Use the full path to output the .gcda file.
This lets the user run the program from a different directory and still have the
.gcda files show up in the correct place.
<rdar://problem/12179524>
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@162855 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Instrumentation/GCOVProfiling.cpp')
-rw-r--r-- | lib/Transforms/Instrumentation/GCOVProfiling.cpp | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/lib/Transforms/Instrumentation/GCOVProfiling.cpp b/lib/Transforms/Instrumentation/GCOVProfiling.cpp index 293bad32c8..f01c6d5a9e 100644 --- a/lib/Transforms/Instrumentation/GCOVProfiling.cpp +++ b/lib/Transforms/Instrumentation/GCOVProfiling.cpp @@ -91,7 +91,7 @@ namespace { void insertCounterWriteout(ArrayRef<std::pair<GlobalVariable*, MDNode*> >); void insertIndirectCounterIncrement(); - std::string mangleName(DICompileUnit CU, std::string NewStem); + std::string mangleName(DICompileUnit CU, const char *NewStem); bool EmitNotes; bool EmitData; @@ -328,7 +328,10 @@ namespace { }; } -std::string GCOVProfiler::mangleName(DICompileUnit CU, std::string NewStem) { +std::string GCOVProfiler::mangleName(DICompileUnit CU, const char *NewStem) { + SmallString<128> Filename = CU.getFilename(); + bool AsString = false; + if (NamedMDNode *GCov = M->getNamedMetadata("llvm.gcov")) { for (int i = 0, e = GCov->getNumOperands(); i != e; ++i) { MDNode *N = GCov->getOperand(i); @@ -337,16 +340,25 @@ std::string GCOVProfiler::mangleName(DICompileUnit CU, std::string NewStem) { MDNode *CompileUnit = dyn_cast<MDNode>(N->getOperand(1)); if (!GCovFile || !CompileUnit) continue; if (CompileUnit == CU) { - SmallString<128> Filename = GCovFile->getString(); - sys::path::replace_extension(Filename, NewStem); - return Filename.str(); + Filename = GCovFile->getString(); + AsString = true; + break; } } } - SmallString<128> Filename = CU.getFilename(); + if (sys::path::is_relative(Filename.c_str())) { + SmallString<128> FullPath = CU.getDirectory(); + sys::path::append(FullPath, Filename.begin(), Filename.end()); + Filename = FullPath; + } + sys::path::replace_extension(Filename, NewStem); - return sys::path::filename(Filename.str()); + + if (!AsString) + return sys::path::filename(Filename.str()); + + return Filename.str(); } bool GCOVProfiler::runOnModule(Module &M) { |