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

Zequan Wu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 14 11:32:25 PDT 2022


zequanwu created this revision.
zequanwu added reviewers: hans, vsk.
Herald added a project: All.
zequanwu requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129791

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


Index: llvm/tools/llvm-cov/CodeCoverage.cpp
===================================================================
--- llvm/tools/llvm-cov/CodeCoverage.cpp
+++ llvm/tools/llvm-cov/CodeCoverage.cpp
@@ -26,6 +26,7 @@
 #include "llvm/ProfileData/Coverage/CoverageMapping.h"
 #include "llvm/ProfileData/InstrProfReader.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Format.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -1053,7 +1054,7 @@
 
   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 +1171,12 @@
     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 +1226,12 @@
     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");
Index: llvm/test/tools/llvm-cov/misssing-profdata.test
===================================================================
--- llvm/test/tools/llvm-cov/misssing-profdata.test
+++ llvm/test/tools/llvm-cov/misssing-profdata.test
@@ -1,2 +1,8 @@
-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
+CHECK: nonexistent.profdata: Could not read profile data
+
+RUN: not llvm-cov export -instr-profile=%t.nonexistent.profdata %t.nonexistent 2>&1 | FileCheck %s
+CHECK: nonexistent.profdata: Could not read profile data
+
+RUN: not llvm-cov report -instr-profile=%t.nonexistent.profdata %t.nonexistent 2>&1 | FileCheck %s
+CHECK: nonexistent.profdata: Could not read profile data


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129791.444747.patch
Type: text/x-patch
Size: 2255 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220714/e2db5899/attachment.bin>


More information about the llvm-commits mailing list