From c0bc461999fdac918dd26867947c24eb6235c8d0 Mon Sep 17 00:00:00 2001 From: Aiden Grossman Date: Fri, 16 Sep 2022 19:35:50 +0000 Subject: [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 --- clang/lib/CodeGen/CodeGenModule.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index bbd4295..06ad67a4 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -182,15 +182,11 @@ CodeGenModule::CodeGenModule(ASTContext &C, if (CodeGenOpts.hasProfileClangUse()) { auto ReaderOrErr = llvm::IndexedInstrProfReader::create( CodeGenOpts.ProfileInstrumentUsePath, CodeGenOpts.ProfileRemappingFile); - if (auto E = ReaderOrErr.takeError()) { - unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, - "Could not read profile %0: %1"); - llvm::handleAllErrors(std::move(E), [&](const llvm::ErrorInfoBase &EI) { - getDiags().Report(DiagID) << CodeGenOpts.ProfileInstrumentUsePath - << EI.message(); - }); - } else - PGOReader = std::move(ReaderOrErr.get()); + // We're checking for profile read errors in CompilerInvocation, so if + // there was an error it should've already been caught. If it hasn't been + // somehow, trip an assertion. + assert(ReaderOrErr); + PGOReader = std::move(ReaderOrErr.get()); } // If coverage mapping generation is enabled, create the -- cgit v1.1