[llvm] r296900 - [sancov] better input parameters validation

Mike Aizatsky via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 3 10:22:20 PST 2017


Author: aizatsky
Date: Fri Mar  3 12:22:20 2017
New Revision: 296900

URL: http://llvm.org/viewvc/llvm-project?rev=296900&view=rev
Log:
[sancov] better input parameters validation

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

Added:
    llvm/trunk/test/tools/sancov/validation.test
Modified:
    llvm/trunk/test/tools/sancov/AArch64/print_coverage_pcs.test
    llvm/trunk/tools/sancov/sancov.cc

Modified: llvm/trunk/test/tools/sancov/AArch64/print_coverage_pcs.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/sancov/AArch64/print_coverage_pcs.test?rev=296900&r1=296899&r2=296900&view=diff
==============================================================================
--- llvm/trunk/test/tools/sancov/AArch64/print_coverage_pcs.test (original)
+++ llvm/trunk/test/tools/sancov/AArch64/print_coverage_pcs.test Fri Mar  3 12:22:20 2017
@@ -1,4 +1,4 @@
 REQUIRES: aarch64-registered-target
 RUN: not sancov -print-coverage-pcs %p/../Inputs/test-linux_android_aarch64 2>&1 | FileCheck %s --check-prefix=AARCH64
 
-AARCH64: Error: __sanitizer_cov* functions not found
+AARCH64: ERROR: __sanitizer_cov* functions not found

Added: llvm/trunk/test/tools/sancov/validation.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/sancov/validation.test?rev=296900&view=auto
==============================================================================
--- llvm/trunk/test/tools/sancov/validation.test (added)
+++ llvm/trunk/test/tools/sancov/validation.test Fri Mar  3 12:22:20 2017
@@ -0,0 +1,6 @@
+REQUIRES: x86_64-linux
+RUN: not sancov -covered-functions %p/Inputs/test-linux_x86_64 2>&1 | FileCheck --check-prefix=NOCFILE %s
+
+NOCFILE: WARNING: No coverage file for {{.*}}test-linux_x86_64
+NOCFILE: ERROR: No valid coverage files given.
+

Modified: llvm/trunk/tools/sancov/sancov.cc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/sancov/sancov.cc?rev=296900&r1=296899&r2=296900&view=diff
==============================================================================
--- llvm/trunk/tools/sancov/sancov.cc (original)
+++ llvm/trunk/tools/sancov/sancov.cc Fri Mar  3 12:22:20 2017
@@ -180,7 +180,7 @@ struct CoverageStats {
 // --------- ERROR HANDLING ---------
 
 static void fail(const llvm::Twine &E) {
-  errs() << "Error: " << E << "\n";
+  errs() << "ERROR: " << E << "\n";
   exit(1);
 }
 
@@ -192,7 +192,7 @@ static void failIf(bool B, const llvm::T
 static void failIfError(std::error_code Error) {
   if (!Error)
     return;
-  errs() << "Error: " << Error.message() << "(" << Error.value() << ")\n";
+  errs() << "ERROR: " << Error.message() << "(" << Error.value() << ")\n";
   exit(1);
 }
 
@@ -202,7 +202,7 @@ template <typename T> static void failIf
 
 static void failIfError(Error Err) {
   if (Err) {
-    logAllUnhandledErrors(std::move(Err), errs(), "Error: ");
+    logAllUnhandledErrors(std::move(Err), errs(), "ERROR: ");
     exit(1);
   }
 }
@@ -1086,6 +1086,9 @@ static void readAndPrintRawCoverage(cons
 
 static std::unique_ptr<SymbolizedCoverage>
 merge(const std::vector<std::unique_ptr<SymbolizedCoverage>> &Coverages) {
+  if (Coverages.empty())
+    return nullptr;
+
   auto Result = make_unique<SymbolizedCoverage>();
 
   for (size_t I = 0; I < Coverages.size(); ++I) {
@@ -1168,11 +1171,17 @@ readSymbolizeAndMergeCmdArguments(std::v
       CoverageByObjFile[Iter->second].push_back(FileName);
     };
 
+    for (const auto &Pair : ObjFiles) {
+      auto FileName = Pair.second;
+      if (CoverageByObjFile.find(FileName) == CoverageByObjFile.end())
+        errs() << "WARNING: No coverage file for " << FileName << "\n";
+    }
+
     // Read raw coverage and symbolize it.
     for (const auto &Pair : CoverageByObjFile) {
       if (findSanitizerCovFunctions(Pair.first).empty()) {
         errs()
-            << "Ignoring " << Pair.first
+            << "WARNING: Ignoring " << Pair.first
             << " and its coverage because  __sanitizer_cov* functions were not "
                "found.\n";
         continue;




More information about the llvm-commits mailing list