Index: test/tools/llvm-cov/Inputs/sources_specified/abs.h =================================================================== --- /dev/null +++ test/tools/llvm-cov/Inputs/sources_specified/abs.h @@ -0,0 +1,5 @@ +int abs(int x) { + if (x < 0) + return -x; + return x; +} Index: test/tools/llvm-cov/Inputs/sources_specified/extra/dec.h =================================================================== --- /dev/null +++ test/tools/llvm-cov/Inputs/sources_specified/extra/dec.h @@ -0,0 +1,3 @@ +int dec(int x) { + return x + 1; +} Index: test/tools/llvm-cov/Inputs/sources_specified/extra/inc.h =================================================================== --- /dev/null +++ test/tools/llvm-cov/Inputs/sources_specified/extra/inc.h @@ -0,0 +1,3 @@ +int inc(int x) { + return x + 1; +} Index: test/tools/llvm-cov/Inputs/sources_specified/main.cc =================================================================== --- /dev/null +++ test/tools/llvm-cov/Inputs/sources_specified/main.cc @@ -0,0 +1,9 @@ +#include "abs.h" +#include "extra/dec.h" +#include "extra/inc.h" + +int main() { + int x = 0; + inc(x); + return abs(x); +} Index: test/tools/llvm-cov/sources-specified.test =================================================================== --- /dev/null +++ test/tools/llvm-cov/sources-specified.test @@ -0,0 +1,28 @@ +RUN: llvm-cov report -instr-profile %S/Inputs/sources_specified/main.profdata \ +RUN: %S/Inputs/sources_specified/main.covmapping \ +RUN: %S/Inputs/sources_specified/main.cc %S/Inputs/sources_specified/extra \ +RUN: | FileCheck -check-prefix=REPORT %s + +RUN: llvm-cov show -instr-profile %S/Inputs/sources_specified/main.profdata \ +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 + + +REPORT: {{^}}main.cc{{.*}} +REPORT: {{^}}extra{{[/\\]}}{{dec|inc}}.h{{.*}} +REPORT: {{^}}extra{{[/\\]}}{{dec|inc}}.h{{.*}} +REPORT-NOT: {{^}}abs.h{{.*}} + +SHOW: {{.*}}main.cc{{.*}} +SHOW: {{.*}}extra{{[/\\]}}{{dec|inc}}.h{{.*}} +SHOW: {{.*}}extra{{[/\\]}}{{dec|inc}}.h{{.*}} +SHOW-NOT: {{.*}}abs.h{{.*}} + +Instructions for regenerating the test: + +clang -mllvm -enable-name-compression=false -fprofile-instr-generate -fcoverage-mapping main.cc -o main + +LLVM_PROFILE_FILE="main.raw" ./main +llvm-profdata merge main.raw -o main.profdata +llvm-cov convert-for-testing ./main -o ./main.covmapping Index: tools/llvm-cov/CodeCoverage.cpp =================================================================== --- tools/llvm-cov/CodeCoverage.cpp +++ tools/llvm-cov/CodeCoverage.cpp @@ -947,7 +947,10 @@ CoverageReport Report(ViewOpts, *Coverage.get()); if (!ShowFunctionSummaries) { - Report.renderFileReports(llvm::outs()); + if (SourceFiles.empty()) + Report.renderFileReports(llvm::outs()); + else + Report.renderFileReports(llvm::outs(), SourceFiles); } else { if (SourceFiles.empty()) { error("Source files must be specified when -show-functions=true is " Index: tools/llvm-cov/CoverageReport.h =================================================================== --- tools/llvm-cov/CoverageReport.h +++ tools/llvm-cov/CoverageReport.h @@ -47,6 +47,9 @@ /// Render file reports for every unique file in the coverage mapping. void renderFileReports(raw_ostream &OS) const; + /// Render file reports for the files specified in \p Files. + void renderFileReports(raw_ostream &OS, ArrayRef Files) const; + /// Render file reports for the files specified in \p Files and the functions /// in \p Filters. void renderFileReports(raw_ostream &OS, ArrayRef Files, Index: tools/llvm-cov/CoverageReport.cpp =================================================================== --- tools/llvm-cov/CoverageReport.cpp +++ tools/llvm-cov/CoverageReport.cpp @@ -364,7 +364,12 @@ std::vector UniqueSourceFiles; for (StringRef SF : Coverage.getUniqueSourceFiles()) UniqueSourceFiles.emplace_back(SF.str()); - renderFileReports(OS, UniqueSourceFiles, CoverageFiltersMatchAll()); + renderFileReports(OS, UniqueSourceFiles); +} + +void CoverageReport::renderFileReports( + raw_ostream &OS, ArrayRef Files) const { + renderFileReports(OS, Files, CoverageFiltersMatchAll()); } void CoverageReport::renderFileReports(