]> granicus.if.org Git - llvm/commitdiff
[llvm-cov] Filter away source files that aren't in the coverage mapping
authorVedant Kumar <vsk@apple.com>
Fri, 23 Sep 2016 18:57:35 +0000 (18:57 +0000)
committerVedant Kumar <vsk@apple.com>
Fri, 23 Sep 2016 18:57:35 +0000 (18:57 +0000)
... so that they don't show up in the index. This came up because polly
contains a .git directory and some other unmapped input in its source
dir.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282282 91177308-0d34-0410-b5e6-96231b3b80d8

test/tools/llvm-cov/report.cpp
tools/llvm-cov/CodeCoverage.cpp

index 824442f99c434653e0e9f2b7cad86b8f8d558d63..c28dd7589408be46ffecbaf29401542a10571ef4 100644 (file)
@@ -1,5 +1,6 @@
 // RUN: llvm-cov report %S/Inputs/report.covmapping -instr-profile %S/Inputs/report.profdata -filename-equivalence 2>&1 | FileCheck %s
-// RUN: llvm-cov report %S/Inputs/report.covmapping -instr-profile %S/Inputs/report.profdata -filename-equivalence report.cpp 2>&1 | FileCheck -check-prefix=FILT-NEXT %s
+// RUN: llvm-cov report %S/Inputs/report.covmapping -instr-profile %S/Inputs/report.profdata -filename-equivalence report.cpp 2>&1 | FileCheck -check-prefix=FILT %s
+// RUN: llvm-cov report %S/Inputs/report.covmapping -instr-profile %S/Inputs/report.profdata -filename-equivalence report.cpp does-not-exist.cpp 2>&1 | FileCheck -check-prefix=FILT %s
 
 // CHECK: Regions    Missed Regions     Cover   Functions  Missed Functions  Executed  Instantiations   Missed Insts.  Executed       Lines      Missed Lines     Cover
 // CHECK-NEXT: ---
index 51ac6ef3d8847ba563eb0b8de100b98a6d9f7327..9230d01778cc58ef2157501f21216e0f5a049aa4 100644 (file)
@@ -332,19 +332,35 @@ std::unique_ptr<CoverageMapping> CodeCoverageTool::load() {
   if (Mismatched)
     warning(utostr(Mismatched) + " functions have mismatched data");
 
-  if (CompareFilenamesOnly) {
-    auto CoveredFiles = Coverage.get()->getUniqueSourceFiles();
+  std::vector<StringRef> CoveredFiles = Coverage.get()->getUniqueSourceFiles();
+
+  auto UncoveredFilesIt = SourceFiles.end();
+  if (!CompareFilenamesOnly) {
+    // The user may have specified source files which aren't in the coverage
+    // mapping. Filter these files away.
+    UncoveredFilesIt = std::remove_if(
+        SourceFiles.begin(), SourceFiles.end(), [&](const std::string &SF) {
+          return !std::binary_search(CoveredFiles.begin(), CoveredFiles.end(),
+                                     SF);
+        });
+  } else {
     for (auto &SF : SourceFiles) {
       StringRef SFBase = sys::path::filename(SF);
-      for (const auto &CF : CoveredFiles)
+      for (const auto &CF : CoveredFiles) {
         if (SFBase == sys::path::filename(CF)) {
           RemappedFilenames[CF] = SF;
           SF = CF;
           break;
         }
+      }
     }
+    UncoveredFilesIt = std::remove_if(
+        SourceFiles.begin(), SourceFiles.end(),
+        [&](const std::string &SF) { return !RemappedFilenames.count(SF); });
   }
 
+  SourceFiles.erase(UncoveredFilesIt, SourceFiles.end());
+
   demangleSymbols(*Coverage);
 
   return Coverage;