summaryrefslogtreecommitdiffstats
path: root/lib/CodeGen/CoverageMappingGen.cpp
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2016-07-18 21:01:27 +0000
committerVedant Kumar <vsk@apple.com>2016-07-18 21:01:27 +0000
commitbca87a6cb2406cc6b6262af8d4a7c06de623065c (patch)
treed90342a68a89efa022e97a18dbce8ea891823861 /lib/CodeGen/CoverageMappingGen.cpp
parent5de4c509d166eaa7cebb7c95e45e6f95ce314d51 (diff)
[Coverage] Normalize '..' out of filename strings
This fixes the issue of having duplicate entries for the same file in a coverage report s.t none of the entries actually displayed the correct coverage information. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@275913 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CoverageMappingGen.cpp')
-rw-r--r--lib/CodeGen/CoverageMappingGen.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/CodeGen/CoverageMappingGen.cpp b/lib/CodeGen/CoverageMappingGen.cpp
index b4dd1a9303..c5495de3b5 100644
--- a/lib/CodeGen/CoverageMappingGen.cpp
+++ b/lib/CodeGen/CoverageMappingGen.cpp
@@ -23,6 +23,7 @@
#include "llvm/ProfileData/Coverage/CoverageMappingWriter.h"
#include "llvm/ProfileData/InstrProfReader.h"
#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
using namespace clang;
using namespace CodeGen;
@@ -920,16 +921,24 @@ struct CounterCoverageMappingBuilder
// propagate counts into them.
}
};
-}
-static bool isMachO(const CodeGenModule &CGM) {
+bool isMachO(const CodeGenModule &CGM) {
return CGM.getTarget().getTriple().isOSBinFormatMachO();
}
-static StringRef getCoverageSection(const CodeGenModule &CGM) {
+StringRef getCoverageSection(const CodeGenModule &CGM) {
return llvm::getInstrProfCoverageSectionName(isMachO(CGM));
}
+std::string normalizeFilename(StringRef Filename) {
+ llvm::SmallString<256> Path(Filename);
+ llvm::sys::path::remove_dots(Path, /*remove_dot_dots=*/true);
+ llvm::sys::fs::make_absolute(Path);
+ return Path.str().str();
+}
+
+} // end anonymous namespace
+
static void dump(llvm::raw_ostream &OS, StringRef FunctionName,
ArrayRef<CounterExpression> Expressions,
ArrayRef<CounterMappingRegion> Regions) {
@@ -994,7 +1003,7 @@ void CoverageMappingModuleGen::addFunctionMappingRecord(
llvm::SmallVector<StringRef, 16> FilenameRefs;
FilenameRefs.resize(FileEntries.size());
for (const auto &Entry : FileEntries)
- FilenameRefs[Entry.second] = Entry.first->getName();
+ FilenameRefs[Entry.second] = normalizeFilename(Entry.first->getName());
RawCoverageMappingReader Reader(CoverageMapping, FilenameRefs, Filenames,
Expressions, Regions);
if (Reader.read())
@@ -1015,11 +1024,8 @@ void CoverageMappingModuleGen::emit() {
FilenameStrs.resize(FileEntries.size());
FilenameRefs.resize(FileEntries.size());
for (const auto &Entry : FileEntries) {
- llvm::SmallString<256> Path(Entry.first->getName());
- llvm::sys::fs::make_absolute(Path);
-
auto I = Entry.second;
- FilenameStrs[I] = std::string(Path.begin(), Path.end());
+ FilenameStrs[I] = normalizeFilename(Entry.first->getName());
FilenameRefs[I] = FilenameStrs[I];
}