diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 79da25c13fa3..57a6429c4be9 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -141,11 +141,13 @@ CodeGenModule::CodeGenModule(ASTContext &C, const HeaderSearchOptions &HSO, if (CodeGenOpts.hasProfileClangUse()) { auto ReaderOrErr = llvm::IndexedInstrProfReader::create( CodeGenOpts.ProfileInstrumentUsePath); - if (std::error_code EC = ReaderOrErr.getError()) { + if (auto E = ReaderOrErr.takeError()) { unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, "Could not read profile %0: %1"); - getDiags().Report(DiagID) << CodeGenOpts.ProfileInstrumentUsePath - << EC.message(); + llvm::handleAllErrors(std::move(E), [&](const llvm::ErrorInfoBase &EI) { + getDiags().Report(DiagID) << CodeGenOpts.ProfileInstrumentUsePath + << EI.message(); + }); } else PGOReader = std::move(ReaderOrErr.get()); } diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp index 43bc37c49f7d..c19321b51290 100644 --- a/clang/lib/CodeGen/CodeGenPGO.cpp +++ b/clang/lib/CodeGen/CodeGenPGO.cpp @@ -800,20 +800,21 @@ void CodeGenPGO::loadRegionCounts(llvm::IndexedInstrProfReader *PGOReader, bool IsInMainFile) { CGM.getPGOStats().addVisited(IsInMainFile); RegionCounts.clear(); - llvm::ErrorOr RecordErrorOr = + llvm::Expected RecordExpected = PGOReader->getInstrProfRecord(FuncName, FunctionHash); - if (std::error_code EC = RecordErrorOr.getError()) { - if (EC == llvm::instrprof_error::unknown_function) + if (auto E = RecordExpected.takeError()) { + auto IPE = llvm::InstrProfError::take(std::move(E)); + if (IPE == llvm::instrprof_error::unknown_function) CGM.getPGOStats().addMissing(IsInMainFile); - else if (EC == llvm::instrprof_error::hash_mismatch) + else if (IPE == llvm::instrprof_error::hash_mismatch) CGM.getPGOStats().addMismatched(IsInMainFile); - else if (EC == llvm::instrprof_error::malformed) + else if (IPE == llvm::instrprof_error::malformed) // TODO: Consider a more specific warning for this case. CGM.getPGOStats().addMismatched(IsInMainFile); return; } ProfRecord = - llvm::make_unique(std::move(RecordErrorOr.get())); + llvm::make_unique(std::move(RecordExpected.get())); RegionCounts = ProfRecord->Counts; } diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 1a1bc47b66fe..7c3850eeabe8 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -403,7 +403,8 @@ static void setPGOUseInstrumentor(CodeGenOptions &Opts, const std::string ProfileName) { auto ReaderOrErr = llvm::IndexedInstrProfReader::create(ProfileName); // In error, return silently and let Clang PGOUse report the error message. - if (ReaderOrErr.getError()) { + if (auto E = ReaderOrErr.takeError()) { + llvm::consumeError(std::move(E)); Opts.setProfileUse(CodeGenOptions::ProfileClangInstr); return; }