[llvm] 44d9def - [llvm-cov] Add error message for missing profdata on report and export subcommands.

Zequan Wu via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 15 12:04:35 PDT 2022


Author: Zequan Wu
Date: 2022-07-15T12:03:52-07:00
New Revision: 44d9def78bb557a34b02997f39e9bf43891fa1cf

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

LOG: [llvm-cov] Add error message for missing profdata on report and export subcommands.

When profdata is missing on report and export commands, the error message is
indistinguishable from missing instrumented binary file. This adds the error
message for report and export commands.

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

Added: 
    

Modified: 
    llvm/test/tools/llvm-cov/misssing-profdata.test
    llvm/tools/llvm-cov/CodeCoverage.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-cov/misssing-profdata.test b/llvm/test/tools/llvm-cov/misssing-profdata.test
index 44faeac740719..0ea8fd74e5bb7 100644
--- a/llvm/test/tools/llvm-cov/misssing-profdata.test
+++ b/llvm/test/tools/llvm-cov/misssing-profdata.test
@@ -1,2 +1,5 @@
-RUN: not llvm-cov show -instr-profile=%t.nonexistent %t.nonexistent 2>&1 | FileCheck %s
-CHECK: Could not read profile data
+RUN: not llvm-cov show -instr-profile=%t.nonexistent.profdata %t.nonexistent 2>&1 | FileCheck %s
+RUN: not llvm-cov export -instr-profile=%t.nonexistent.profdata %t.nonexistent 2>&1 | FileCheck %s
+RUN: not llvm-cov report -instr-profile=%t.nonexistent.profdata %t.nonexistent 2>&1 | FileCheck %s
+
+CHECK: nonexistent.profdata: Could not read profile data!

diff  --git a/llvm/tools/llvm-cov/CodeCoverage.cpp b/llvm/tools/llvm-cov/CodeCoverage.cpp
index 6932e9b5bd31a..27e181c129b82 100644
--- a/llvm/tools/llvm-cov/CodeCoverage.cpp
+++ b/llvm/tools/llvm-cov/CodeCoverage.cpp
@@ -1053,7 +1053,7 @@ int CodeCoverageTool::doShow(int argc, const char **argv,
 
   sys::fs::file_status Status;
   if (std::error_code EC = sys::fs::status(PGOFilename, Status)) {
-    error("Could not read profile data!", EC.message());
+    error("Could not read profile data!" + EC.message(), PGOFilename);
     return 1;
   }
 
@@ -1170,6 +1170,12 @@ int CodeCoverageTool::doReport(int argc, const char **argv,
     return 1;
   }
 
+  sys::fs::file_status Status;
+  if (std::error_code EC = sys::fs::status(PGOFilename, Status)) {
+    error("Could not read profile data!" + EC.message(), PGOFilename);
+    return 1;
+  }
+
   auto Coverage = load();
   if (!Coverage)
     return 1;
@@ -1219,6 +1225,12 @@ int CodeCoverageTool::doExport(int argc, const char **argv,
     return 1;
   }
 
+  sys::fs::file_status Status;
+  if (std::error_code EC = sys::fs::status(PGOFilename, Status)) {
+    error("Could not read profile data!" + EC.message(), PGOFilename);
+    return 1;
+  }
+
   auto Coverage = load();
   if (!Coverage) {
     error("Could not load coverage information");


        


More information about the llvm-commits mailing list