aidengrossman created this revision. Herald added a subscriber: wenlei. Herald added a project: All. aidengrossman requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
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. Repository: rG LLVM Github Monorepo 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, + "Could not read 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;
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, + "Could not read 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;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits