[PATCH] D132991: [Clang] Give error message for invalid profile path when compiling IR

Aiden Grossman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 31 13:21:27 PDT 2022


aidengrossman updated this revision to Diff 457074.
aidengrossman added a comment.

Changed error message from "Could not read profile" to "Error in reading profile"
to better reflect the fact that profile reading can fail for multiple reasons, not just
when the file path cannot be read/does not exist.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D132991/new/

https://reviews.llvm.org/D132991

Files:
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Profile/profile-does-not-exist-ir.c


Index: clang/test/Profile/profile-does-not-exist-ir.c
===================================================================
--- /dev/null
+++ clang/test/Profile/profile-does-not-exist-ir.c
@@ -0,0 +1,4 @@
+// RUN: not %clang_cc1 -emit-llvm -x ir %s -o - -fprofile-instrument-use-path=%t.nonexistent.profdata 2>&1 | FileCheck %s
+
+// CHECK: error: Could not read profile {{.*}}.nonexistent.profdata:
+// CHECK-NOT: Assertion failed
Index: clang/lib/Frontend/CompilerInvocation.cpp
===================================================================
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1293,12 +1293,15 @@
 
 // Set the profile kind using fprofile-instrument-use-path.
 static void setPGOUseInstrumentor(CodeGenOptions &Opts,
-                                  const Twine &ProfileName) {
+                                  const Twine &ProfileName,
+                                  DiagnosticsEngine &Diags) {
   auto ReaderOrErr = llvm::IndexedInstrProfReader::create(ProfileName);
-  // In error, return silently and let Clang PGOUse report the error message.
   if (auto E = ReaderOrErr.takeError()) {
-    llvm::consumeError(std::move(E));
-    Opts.setProfileUse(CodeGenOptions::ProfileClangInstr);
+    unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
+                                            "Error in reading profile %0: %1");
+    llvm::handleAllErrors(std::move(E), [&](const llvm::ErrorInfoBase &EI) {
+      Diags.Report(DiagID) << ProfileName.str() << EI.message();
+    });
     return;
   }
   std::unique_ptr<llvm::IndexedInstrProfReader> PGOReader =
@@ -1717,7 +1720,7 @@
   }
 
   if (!Opts.ProfileInstrumentUsePath.empty())
-    setPGOUseInstrumentor(Opts, Opts.ProfileInstrumentUsePath);
+    setPGOUseInstrumentor(Opts, Opts.ProfileInstrumentUsePath, Diags);
 
   if (const Arg *A = Args.getLastArg(OPT_ftime_report, OPT_ftime_report_EQ)) {
     Opts.TimePasses = true;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132991.457074.patch
Type: text/x-patch
Size: 1972 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220831/e08f1f48/attachment.bin>


More information about the cfe-commits mailing list