summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustin Bogner <mail@justinbogner.com>2014-06-27 20:41:25 +0000
committerJustin Bogner <mail@justinbogner.com>2014-06-27 20:41:25 +0000
commit035fcf711534a1988d4d22fa3e273c7f8d7e5c31 (patch)
tree2cfe8154515daa009fbc1594969b8ef0af85b91b
parent3b7ffd63149b086f5d56ba6b9f75f6d36faff7a7 (diff)
downloadbcm5719-llvm-035fcf711534a1988d4d22fa3e273c7f8d7e5c31.tar.gz
bcm5719-llvm-035fcf711534a1988d4d22fa3e273c7f8d7e5c31.zip
llvm-cov: Support specifying multiple source files
Make llvm-cov compatible with gcov for cases where multiple files are specified on the command line. That is, loop over each one and report coverage, and report errors on stderr only rather than via return code. llvm-svn: 211959
-rw-r--r--llvm/test/tools/llvm-cov/llvm-cov.test6
-rw-r--r--llvm/tools/llvm-cov/llvm-cov.cpp57
2 files changed, 34 insertions, 29 deletions
diff --git a/llvm/test/tools/llvm-cov/llvm-cov.test b/llvm/test/tools/llvm-cov/llvm-cov.test
index 82d1273ae61..0d3eb6b8f81 100644
--- a/llvm/test/tools/llvm-cov/llvm-cov.test
+++ b/llvm/test/tools/llvm-cov/llvm-cov.test
@@ -102,12 +102,12 @@ RUN: diff -aub test_no_gcda.cpp.gcov test.cpp.gcov
RUN: diff -aub test_no_gcda.h.gcov test.h.gcov
# Invalid gcno file.
-RUN: not llvm-cov test.c -gcno=test_read_fail.gcno
+RUN: llvm-cov test.c -gcno=test_read_fail.gcno
# Bad file checksum on gcda.
-RUN: not llvm-cov test.c -gcda=test_file_checksum_fail.gcda
+RUN: llvm-cov test.c -gcda=test_file_checksum_fail.gcda
# Bad function checksum on gcda
-RUN: not llvm-cov test.c -gcda=test_func_checksum_fail.gcda
+RUN: llvm-cov test.c -gcda=test_func_checksum_fail.gcda
XFAIL: powerpc64-, s390x, mips-, mips64-, sparc
diff --git a/llvm/tools/llvm-cov/llvm-cov.cpp b/llvm/tools/llvm-cov/llvm-cov.cpp
index 0a64d76c374..04de4431059 100644
--- a/llvm/tools/llvm-cov/llvm-cov.cpp
+++ b/llvm/tools/llvm-cov/llvm-cov.cpp
@@ -24,8 +24,8 @@
#include <system_error>
using namespace llvm;
-static cl::opt<std::string> SourceFile(cl::Positional, cl::Required,
- cl::desc("SOURCEFILE"));
+static cl::list<std::string> SourceFiles(cl::Positional, cl::OneOrMore,
+ cl::desc("SOURCEFILE"));
static cl::opt<bool> AllBlocks("a", cl::Grouping, cl::init(false),
cl::desc("Display all basic blocks"));
@@ -76,15 +76,7 @@ static cl::opt<std::string> InputGCNO("gcno", cl::cat(DebugCat), cl::init(""),
static cl::opt<std::string> InputGCDA("gcda", cl::cat(DebugCat), cl::init(""),
cl::desc("Override inferred gcda file"));
-//===----------------------------------------------------------------------===//
-int main(int argc, char **argv) {
- // Print a stack trace if we signal out.
- sys::PrintStackTraceOnErrorSignal();
- PrettyStackTraceProgram X(argc, argv);
- llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
-
- cl::ParseCommandLineOptions(argc, argv, "LLVM code coverage tool\n");
-
+void reportCoverage(StringRef SourceFile) {
SmallString<128> CoverageFileStem(ObjectDir);
if (CoverageFileStem.empty()) {
// If no directory was specified with -o, look next to the source file.
@@ -97,37 +89,38 @@ int main(int argc, char **argv) {
// A file was given. Ignore the source file and look next to this file.
sys::path::replace_extension(CoverageFileStem, "");
- if (InputGCNO.empty())
- InputGCNO = (CoverageFileStem.str() + ".gcno").str();
- if (InputGCDA.empty())
- InputGCDA = (CoverageFileStem.str() + ".gcda").str();
-
+ std::string GCNO = InputGCNO.empty()
+ ? std::string(CoverageFileStem.str()) + ".gcno"
+ : InputGCNO;
+ std::string GCDA = InputGCDA.empty()
+ ? std::string(CoverageFileStem.str()) + ".gcda"
+ : InputGCDA;
GCOVFile GF;
std::unique_ptr<MemoryBuffer> GCNO_Buff;
- if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCNO, GCNO_Buff)) {
- errs() << InputGCNO << ": " << ec.message() << "\n";
- return 1;
+ if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(GCNO, GCNO_Buff)) {
+ errs() << GCNO << ": " << ec.message() << "\n";
+ return;
}
GCOVBuffer GCNO_GB(GCNO_Buff.get());
if (!GF.readGCNO(GCNO_GB)) {
errs() << "Invalid .gcno File!\n";
- return 1;
+ return;
}
std::unique_ptr<MemoryBuffer> GCDA_Buff;
- if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCDA, GCDA_Buff)) {
+ if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(GCDA, GCDA_Buff)) {
if (ec != errc::no_such_file_or_directory) {
- errs() << InputGCDA << ": " << ec.message() << "\n";
- return 1;
+ errs() << GCDA << ": " << ec.message() << "\n";
+ return;
}
// Clear the filename to make it clear we didn't read anything.
- InputGCDA = "-";
+ GCDA = "-";
} else {
GCOVBuffer GCDA_GB(GCDA_Buff.get());
if (!GF.readGCDA(GCDA_GB)) {
errs() << "Invalid .gcda File!\n";
- return 1;
+ return;
}
}
@@ -138,6 +131,18 @@ int main(int argc, char **argv) {
PreservePaths, UncondBranch, LongNames, NoOutput);
FileInfo FI(Options);
GF.collectLineCounts(FI);
- FI.print(SourceFile, InputGCNO, InputGCDA);
+ FI.print(SourceFile, GCNO, GCDA);
+}
+
+int main(int argc, char **argv) {
+ // Print a stack trace if we signal out.
+ sys::PrintStackTraceOnErrorSignal();
+ PrettyStackTraceProgram X(argc, argv);
+ llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
+
+ cl::ParseCommandLineOptions(argc, argv, "LLVM code coverage tool\n");
+
+ for (const auto &SourceFile : SourceFiles)
+ reportCoverage(SourceFile);
return 0;
}
OpenPOWER on IntegriCloud