[llvm] e92eeaf - [llvm-cov] don't include all source files when provided source files are filtered out

Zequan Wu via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 23 19:32:30 PDT 2020


Author: Zequan Wu
Date: 2020-10-23T19:32:16-07:00
New Revision: e92eeaf3c21923151cf86c706e396b613145f142

URL: https://github.com/llvm/llvm-project/commit/e92eeaf3c21923151cf86c706e396b613145f142
DIFF: https://github.com/llvm/llvm-project/commit/e92eeaf3c21923151cf86c706e396b613145f142.diff

LOG: [llvm-cov] don't include all source files when provided source files are filtered out

When all provided source files are filtered out either due to `--ignore-filename-regex` or not part of binary, don't generate coverage reults for all source files. Because if users want to generate coverage results for all source files, they don't even need to provid selected source files or `--ignore-filename-regex`.

Differential Revision: https://reviews.llvm.org/D89359

Added: 
    

Modified: 
    llvm/test/tools/llvm-cov/native_separators.c
    llvm/test/tools/llvm-cov/sources-specified.test
    llvm/test/tools/llvm-cov/universal_bin_wrapping_archives.test
    llvm/test/tools/llvm-cov/warnings.h
    llvm/tools/llvm-cov/CodeCoverage.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-cov/native_separators.c b/llvm/test/tools/llvm-cov/native_separators.c
index 8ab1a732b995..3c768e1014b9 100644
--- a/llvm/test/tools/llvm-cov/native_separators.c
+++ b/llvm/test/tools/llvm-cov/native_separators.c
@@ -8,7 +8,7 @@
 // RUN: llvm-profdata merge %S/Inputs/double_dots.proftext -o %t.profdata
 // RUN: llvm-cov show %S/Inputs/native_separators.covmapping -instr-profile=%t.profdata -o %t.dir
 // RUN: FileCheck -check-prefixes=TEXT-INDEX -input-file=%t.dir/index.txt %s
-// RUN: llvm-cov show -format=html %S/Inputs/native_separators.covmapping -instr-profile=%t.profdata -path-equivalence=/tmp,%S ../llvm-"config"/../llvm-"cov"/native_separators.c -o %t.dir
+// RUN: llvm-cov show -format=html %S/Inputs/native_separators.covmapping -instr-profile=%t.profdata -path-equivalence=/tmp,%S %S/../llvm-"config"/../llvm-"cov"/native_separators.c -o %t.dir
 // RUN: FileCheck -check-prefixes=HTML-INDEX -input-file=%t.dir/index.html %s
 // RUN: llvm-cov show -format=html %S/Inputs/native_separators.covmapping -instr-profile=%t.profdata -path-equivalence=/tmp,%S %s -o %t.dir
 // RUN: FileCheck -check-prefixes=HTML -input-file=%t.dir/coverage/tmp/native_separators.c.html %s

diff  --git a/llvm/test/tools/llvm-cov/sources-specified.test b/llvm/test/tools/llvm-cov/sources-specified.test
index a20fe538529b..e7a8c11a7f82 100644
--- a/llvm/test/tools/llvm-cov/sources-specified.test
+++ b/llvm/test/tools/llvm-cov/sources-specified.test
@@ -10,6 +10,18 @@ RUN:   %S/Inputs/sources_specified/main.covmapping \
 RUN:   %S/Inputs/sources_specified/main.cc %S/Inputs/sources_specified/extra \
 RUN:   | FileCheck -check-prefix=SHOW %s
 
+# Don't include all source files when provided source files are filtered out.
+RUN: llvm-cov show -instr-profile %S/Inputs/sources_specified/main.profdata \
+RUN:   -path-equivalence=/tmp,%S/Inputs \
+RUN:   %S/Inputs/sources_specified/main.covmapping \
+RUN:   --ignore-filename-regex='.*' \
+RUN:   %S/Inputs/sources_specified/main.cc %S/Inputs/sources_specified/extra \
+RUN:   | FileCheck -allow-empty -check-prefix=IGNORE %s
+
+IGNORE-NOT: {{.*}}main.cc{{.*}}
+IGNORE-NOT: {{.*}}inc.h{{.*}}
+IGNORE-NOT: {{.*}}dec.h{{.*}}
+
 # Order of files may 
diff er, check the total values calculated.
 REPORT-NOT: {{.*}}abs.h{{.*}}
 REPORT: {{^}}TOTAL 3{{.*}}72.73%

diff  --git a/llvm/test/tools/llvm-cov/universal_bin_wrapping_archives.test b/llvm/test/tools/llvm-cov/universal_bin_wrapping_archives.test
index 5c04f7c6ba52..903dae45002e 100644
--- a/llvm/test/tools/llvm-cov/universal_bin_wrapping_archives.test
+++ b/llvm/test/tools/llvm-cov/universal_bin_wrapping_archives.test
@@ -17,11 +17,11 @@ REQUIRES: zlib
 RUN: llvm-profdata merge %S/Inputs/universal_bin_wrapping_archives/universal_bin_wrapping_archives.proftext -o %t.profdata
 
 RUN: llvm-cov show %S/Inputs/universal_bin_wrapping_archives/universal_bin_wrapping_archives \
-RUN:   -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs/universal_bin_wrapping_archives %s -arch i386 \
+RUN:   -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs/universal_bin_wrapping_archives -arch i386 \
 RUN:   | FileCheck %s --check-prefix=SHOW_ARCHIVE
 
 RUN: llvm-cov show %S/Inputs/universal_bin_wrapping_archives/universal_bin_wrapping_archives \
-RUN:   -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs/universal_bin_wrapping_archives %s -arch x86_64 \
+RUN:   -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs/universal_bin_wrapping_archives -arch x86_64 \
 RUN:   | FileCheck %s --check-prefix=SHOW_ARCHIVE
 
 SHOW_ARCHIVE: {{.*}}obj1.c:

diff  --git a/llvm/test/tools/llvm-cov/warnings.h b/llvm/test/tools/llvm-cov/warnings.h
index 5bd62be6d043..52bd6926f281 100644
--- a/llvm/test/tools/llvm-cov/warnings.h
+++ b/llvm/test/tools/llvm-cov/warnings.h
@@ -1,13 +1,13 @@
-// RUN: llvm-cov show %S/Inputs/prevent_false_instantiations.covmapping -instr-profile %S/Inputs/elf_binary_comdat.profdata -path-equivalence=/tmp,%S /dev/null | FileCheck %s -allow-empty -check-prefix=FAKE-FILE-STDOUT
-// RUN: llvm-cov show %S/Inputs/prevent_false_instantiations.covmapping -instr-profile %S/Inputs/elf_binary_comdat.profdata -path-equivalence=/tmp,%S /dev/null 2>&1 | FileCheck %s -check-prefix=FAKE-FILE-STDERR
+// RUN: llvm-cov show %S/Inputs/prevent_false_instantiations.covmapping -instr-profile %S/Inputs/elf_binary_comdat.profdata -path-equivalence=/tmp,%S | FileCheck %s -allow-empty -check-prefix=FAKE-FILE-STDOUT
+// RUN: llvm-cov show %S/Inputs/prevent_false_instantiations.covmapping -instr-profile %S/Inputs/elf_binary_comdat.profdata -path-equivalence=/tmp,%S 2>&1 | FileCheck %s -check-prefix=FAKE-FILE-STDERR
 // RUN: not llvm-cov report %S/Inputs/prevent_false_instantiations.covmapping -instr-profile %S/Inputs/elf_binary_comdat.profdata -format=html
 // RUN: not llvm-cov export %S/Inputs/prevent_false_instantiations.covmapping -instr-profile %S/Inputs/elf_binary_comdat.profdata -format=html
 
 // FAKE-FILE-STDOUT-NOT: warning: The file '{{.*}}' isn't covered.
 // FAKE-FILE-STDERR: warning: The file '{{.*}}' isn't covered.
 
-// RUN: llvm-cov show %S/Inputs/prevent_false_instantiations.covmapping -instr-profile %S/Inputs/elf_binary_comdat.profdata -path-equivalence=/tmp,%S -name ".*" /dev/null | FileCheck %s -allow-empty -check-prefix=FAKE-FUNC-STDOUT
-// RUN: llvm-cov show %S/Inputs/prevent_false_instantiations.covmapping -instr-profile %S/Inputs/elf_binary_comdat.profdata -path-equivalence=/tmp,%S -name-regex ".*" /dev/null 2>&1 | FileCheck %s -check-prefix=FAKE-FUNC-STDERR
+// RUN: llvm-cov show %S/Inputs/prevent_false_instantiations.covmapping -instr-profile %S/Inputs/elf_binary_comdat.profdata -path-equivalence=/tmp,%S -name=".*" | FileCheck %s -allow-empty -check-prefix=FAKE-FUNC-STDOUT
+// RUN: llvm-cov show %S/Inputs/prevent_false_instantiations.covmapping -instr-profile %S/Inputs/elf_binary_comdat.profdata -path-equivalence=/tmp,%S -name-regex=".*" 2>&1 | FileCheck %s -check-prefix=FAKE-FUNC-STDERR
 
 // FAKE-FUNC-STDOUT-NOT: warning: Could not read coverage for '{{.*}}'.
 // FAKE-FUNC-STDERR: Could not read coverage for '{{.*}}'.

diff  --git a/llvm/tools/llvm-cov/CodeCoverage.cpp b/llvm/tools/llvm-cov/CodeCoverage.cpp
index cd3dbc44a66b..702c03237f17 100644
--- a/llvm/tools/llvm-cov/CodeCoverage.cpp
+++ b/llvm/tools/llvm-cov/CodeCoverage.cpp
@@ -130,6 +130,9 @@ class CodeCoverageTool {
   CoverageFiltersMatchAll Filters;
   CoverageFilters IgnoreFilenameFilters;
 
+  /// True if InputSourceFiles are provided.
+  bool HadSourceFiles = false;
+
   /// The path to the indexed profile.
   std::string PGOFilename;
 
@@ -194,6 +197,7 @@ void CodeCoverageTool::addCollectedPath(const std::string &Path) {
   sys::path::remove_dots(EffectivePath, /*remove_dot_dots=*/true);
   if (!IgnoreFilenameFilters.matchesFilename(EffectivePath))
     SourceFiles.emplace_back(EffectivePath.str());
+  HadSourceFiles = !SourceFiles.empty();
 }
 
 void CodeCoverageTool::collectPaths(const std::string &Path) {
@@ -397,6 +401,7 @@ void CodeCoverageTool::remapPathNames(const CoverageMapping &Coverage) {
     sys::path::native(Path, NativePath);
     if (!sys::path::is_separator(NativePath.back()))
       NativePath += sys::path::get_separator();
+    sys::path::remove_dots(NativePath, true);
     return NativePath.c_str();
   };
   std::string RemapFrom = nativeWithTrailing(PathRemapping->first);
@@ -406,6 +411,7 @@ void CodeCoverageTool::remapPathNames(const CoverageMapping &Coverage) {
   for (StringRef Filename : Coverage.getUniqueSourceFiles()) {
     SmallString<128> NativeFilename;
     sys::path::native(Filename, NativeFilename);
+    sys::path::remove_dots(NativeFilename, true);
     if (NativeFilename.startswith(RemapFrom)) {
       RemappedFilenames[Filename] =
           RemapTo + NativeFilename.substr(RemapFrom.size()).str();
@@ -895,7 +901,7 @@ int CodeCoverageTool::doShow(int argc, const char **argv,
 
   auto Printer = CoveragePrinter::create(ViewOpts);
 
-  if (SourceFiles.empty())
+  if (SourceFiles.empty() && !HadSourceFiles)
     // Get the source files from the function coverage mapping.
     for (StringRef Filename : Coverage->getUniqueSourceFiles()) {
       if (!IgnoreFilenameFilters.matchesFilename(Filename))


        


More information about the llvm-commits mailing list