[llvm] r200417 - llvm-cov: Expect a source file as a positional parameter

Justin Bogner mail at justinbogner.com
Wed Jan 29 13:31:37 PST 2014


Author: bogner
Date: Wed Jan 29 15:31:34 2014
New Revision: 200417

URL: http://llvm.org/viewvc/llvm-project?rev=200417&view=rev
Log:
llvm-cov: Expect a source file as a positional parameter

Currently, llvm-cov isn't command-line compatible with gcov, which
accepts a source file name as its first parameter and infers the gcno
and gcda file names from that. This change keeps our -gcda and -gcno
options available for convenience in overriding this behaviour, but
adds the required parameter and inference behaviour as a compatible
default.

Modified:
    llvm/trunk/test/tools/llvm-cov/llvm-cov.test
    llvm/trunk/tools/llvm-cov/llvm-cov.cpp

Modified: llvm/trunk/test/tools/llvm-cov/llvm-cov.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/llvm-cov.test?rev=200417&r1=200416&r2=200417&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/llvm-cov.test (original)
+++ llvm/trunk/test/tools/llvm-cov/llvm-cov.test Wed Jan 29 15:31:34 2014
@@ -5,34 +5,34 @@ RUN: mkdir %t
 RUN: cd %t
 RUN: cp %p/Inputs/test* .
 
-RUN: llvm-cov -gcno=test.gcno -gcda=test.gcda | diff test_no_options.output -
-RUN: llvm-cov -gcno=test.gcno -gcda=test.gcda -f | diff test_-f.output -
+RUN: llvm-cov test.c | diff test_no_options.output -
+RUN: llvm-cov test.c -f | diff test_-f.output -
 RUN: diff -aub test_no_options.cpp.gcov test.cpp.gcov
 RUN: diff -aub test_no_options.h.gcov test.h.gcov
 
-RUN: llvm-cov -gcno=test.gcno -gcda=test.gcda -a
+RUN: llvm-cov test.c -a
 RUN: diff -aub test_-a.cpp.gcov test.cpp.gcov
 RUN: diff -aub test_-a.h.gcov test.h.gcov
 
-RUN: llvm-cov -gcno=test.gcno -gcda=test.gcda -a -b | diff test_-b.output -
+RUN: llvm-cov test.c -a -b | diff test_-b.output -
 # This is expected to fail because gcov doesn't actually output real branch or
 # call statistics on a per function basis.
-RUN: llvm-cov -gcno=test.gcno -gcda=test.gcda -a -b -f | not diff test_-b_-f.output -
+RUN: llvm-cov test.c -a -b -f | not diff test_-b_-f.output -
 RUN: diff -aub test_-a_-b.cpp.gcov test.cpp.gcov
 RUN: diff -aub test_-a_-b.h.gcov test.h.gcov
 
-RUN: llvm-cov -gcno=test.gcno -gcda=test.gcda -a -b -u
+RUN: llvm-cov test.c -a -b -u
 RUN: diff -aub test_-a_-b_-u.cpp.gcov test.cpp.gcov
 RUN: diff -aub test_-a_-b_-u.h.gcov test.h.gcov
 
-RUN: llvm-cov -gcno=test.gcno -gcda=test.gcda -a -b -c -u
+RUN: llvm-cov test.c -a -b -c -u
 RUN: diff -aub test_-a_-b_-c_-u.cpp.gcov test.cpp.gcov
 RUN: diff -aub test_-a_-b_-c_-u.h.gcov test.h.gcov
 
-RUN: not llvm-cov -gcno=test_read_fail.gcno -gcda=test.gcda
+RUN: not llvm-cov test.c -gcno=test_read_fail.gcno
 
-RUN: not llvm-cov -gcno=test.gcno -gcda=test_file_checksum_fail.gcda
+RUN: not llvm-cov test.c -gcda=test_file_checksum_fail.gcda
 
-RUN: not llvm-cov -gcno=test.gcno -gcda=test_func_checksum_fail.gcda
+RUN: not llvm-cov test.c -gcda=test_func_checksum_fail.gcda
 
 XFAIL: powerpc64, s390x, mips, sparc

Modified: llvm/trunk/tools/llvm-cov/llvm-cov.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/llvm-cov.cpp?rev=200417&r1=200416&r2=200417&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/llvm-cov.cpp (original)
+++ llvm/trunk/tools/llvm-cov/llvm-cov.cpp Wed Jan 29 15:31:34 2014
@@ -21,6 +21,9 @@
 #include "llvm/Support/system_error.h"
 using namespace llvm;
 
+static cl::opt<std::string> SourceFile(cl::Positional, cl::Required,
+                                       cl::desc("SOURCEFILE"));
+
 static cl::opt<bool>
 DumpGCOV("dump", cl::init(false), cl::desc("dump gcov file"));
 
@@ -56,9 +59,12 @@ int main(int argc, char **argv) {
 
   cl::ParseCommandLineOptions(argc, argv, "llvm coverage tool\n");
 
-  GCOVFile GF;
   if (InputGCNO.empty())
-    errs() << " " << argv[0] << ": No gcov input file!\n";
+    InputGCNO = SourceFile.substr(0, SourceFile.rfind(".")) + ".gcno";
+  if (InputGCDA.empty())
+    InputGCDA = SourceFile.substr(0, SourceFile.rfind(".")) + ".gcda";
+
+  GCOVFile GF;
 
   OwningPtr<MemoryBuffer> GCNO_Buff;
   if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCNO, GCNO_Buff)) {
@@ -71,17 +77,15 @@ int main(int argc, char **argv) {
     return 1;
   }
 
-  if (!InputGCDA.empty()) {
-    OwningPtr<MemoryBuffer> GCDA_Buff;
-    if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCDA, GCDA_Buff)) {
-      errs() << InputGCDA << ": " << ec.message() << "\n";
-      return 1;
-    }
-    GCOVBuffer GCDA_GB(GCDA_Buff.get());
-    if (!GF.readGCDA(GCDA_GB)) {
-      errs() << "Invalid .gcda File!\n";
-      return 1;
-    }
+  OwningPtr<MemoryBuffer> GCDA_Buff;
+  if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCDA, GCDA_Buff)) {
+    errs() << InputGCDA << ": " << ec.message() << "\n";
+    return 1;
+  }
+  GCOVBuffer GCDA_GB(GCDA_Buff.get());
+  if (!GF.readGCDA(GCDA_GB)) {
+    errs() << "Invalid .gcda File!\n";
+    return 1;
   }
 
   if (DumpGCOV)





More information about the llvm-commits mailing list