aidengrossman updated this revision to Diff 457179. aidengrossman added a comment.
Fix tests and replace error message in CodeGenModule with assertion since we're now capturing the error message in CompileInvocation. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D132991/new/ https://reviews.llvm.org/D132991 Files: clang/lib/CodeGen/CodeGenModule.cpp clang/lib/Frontend/CompilerInvocation.cpp clang/test/Profile/profile-does-not-exist-ir.c clang/test/Profile/profile-does-not-exist.c Index: clang/test/Profile/profile-does-not-exist.c =================================================================== --- clang/test/Profile/profile-does-not-exist.c +++ clang/test/Profile/profile-does-not-exist.c @@ -1,4 +1,4 @@ // RUN: not %clang_cc1 -emit-llvm %s -o - -fprofile-instrument-use-path=%t.nonexistent.profdata 2>&1 | FileCheck %s -// CHECK: error: Could not read profile {{.*}}.nonexistent.profdata: +// CHECK: error: Error in reading profile {{.*}}.nonexistent.profdata: // CHECK-NOT: Assertion failed 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: Error in reading 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; Index: clang/lib/CodeGen/CodeGenModule.cpp =================================================================== --- clang/lib/CodeGen/CodeGenModule.cpp +++ clang/lib/CodeGen/CodeGenModule.cpp @@ -182,15 +182,11 @@ 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
Index: clang/test/Profile/profile-does-not-exist.c =================================================================== --- clang/test/Profile/profile-does-not-exist.c +++ clang/test/Profile/profile-does-not-exist.c @@ -1,4 +1,4 @@ // RUN: not %clang_cc1 -emit-llvm %s -o - -fprofile-instrument-use-path=%t.nonexistent.profdata 2>&1 | FileCheck %s -// CHECK: error: Could not read profile {{.*}}.nonexistent.profdata: +// CHECK: error: Error in reading profile {{.*}}.nonexistent.profdata: // CHECK-NOT: Assertion failed 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: Error in reading 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; Index: clang/lib/CodeGen/CodeGenModule.cpp =================================================================== --- clang/lib/CodeGen/CodeGenModule.cpp +++ clang/lib/CodeGen/CodeGenModule.cpp @@ -182,15 +182,11 @@ 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
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits