diff options
author | Aiden Grossman <agrossman154@yahoo.com> | 2022-09-16 19:35:50 +0000 |
---|---|---|
committer | Aiden Grossman <agrossman154@yahoo.com> | 2022-09-16 19:45:57 +0000 |
commit | c0bc461999fdac918dd26867947c24eb6235c8d0 (patch) | |
tree | 49c00ed268837a53a0143816fd116d94cb5bf637 /clang/lib/Frontend/CompilerInvocation.cpp | |
parent | 8a868d8859f9da23ee051848863045208c17ab47 (diff) | |
download | llvm-c0bc461999fdac918dd26867947c24eb6235c8d0.zip llvm-c0bc461999fdac918dd26867947c24eb6235c8d0.tar.gz llvm-c0bc461999fdac918dd26867947c24eb6235c8d0.tar.bz2 |
[Clang] Give error message for invalid profile path when compiling IR
Before this patch, when compiling an IR file (eg the .llvmbc section
from an object file compiled with -Xclang -fembed-bitcode=all) and
profile data was passed in using the -fprofile-instrument-use-path
flag, there would be no error printed (as the previous implementation
relied on the error getting caught again in the constructor of
CodeGenModule which isn't called when -x ir is set). This patch
moves the error checking directly to where the error is caught
originally rather than failing silently in setPGOUseInstrumentor and
waiting to catch it in CodeGenModule to print diagnostic information to
the user.
Regression test added.
Reviewed By: xur, mtrofin
Differential Revision: https://reviews.llvm.org/D132991
Diffstat (limited to 'clang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index f42bf30..9f92410 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -1293,12 +1293,15 @@ static std::string serializeXRayInstrumentationBundle(const XRayInstrSet &S) { // 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 = @@ -1712,7 +1715,7 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, } 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; |