diff options
Diffstat (limited to 'llvm/lib/LTO/LTO.cpp')
-rw-r--r-- | llvm/lib/LTO/LTO.cpp | 46 |
1 files changed, 17 insertions, 29 deletions
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp index cf40bfd4ebc..f867582454d 100644 --- a/llvm/lib/LTO/LTO.cpp +++ b/llvm/lib/LTO/LTO.cpp @@ -104,17 +104,16 @@ std::unique_ptr<Module> llvm::loadModuleFromBuffer(const MemoryBufferRef &Buffer, LLVMContext &Context, bool Lazy) { SMDiagnostic Err; - ErrorOr<std::unique_ptr<Module>> ModuleOrErr(nullptr); - if (Lazy) { - ModuleOrErr = getLazyBitcodeModule(Buffer, Context, - /* ShouldLazyLoadMetadata */ Lazy); - } else { - ModuleOrErr = parseBitcodeFile(Buffer, Context); - } - if (std::error_code EC = ModuleOrErr.getError()) { - Err = SMDiagnostic(Buffer.getBufferIdentifier(), SourceMgr::DK_Error, - EC.message()); - Err.print("ThinLTO", errs()); + Expected<std::unique_ptr<Module>> ModuleOrErr = + Lazy ? getLazyBitcodeModule(Buffer, Context, + /* ShouldLazyLoadMetadata */ true) + : parseBitcodeFile(Buffer, Context); + if (!ModuleOrErr) { + handleAllErrors(ModuleOrErr.takeError(), [&](ErrorInfoBase &EIB) { + SMDiagnostic Err = SMDiagnostic(Buffer.getBufferIdentifier(), + SourceMgr::DK_Error, EIB.message()); + Err.print("ThinLTO", errs()); + }); report_fatal_error("Can't load module, abort."); } return std::move(ModuleOrErr.get()); @@ -204,25 +203,13 @@ void llvm::thinLTOInternalizeAndPromoteInIndex( Expected<std::unique_ptr<InputFile>> InputFile::create(MemoryBufferRef Object) { std::unique_ptr<InputFile> File(new InputFile); - std::string Msg; - auto DiagHandler = [](const DiagnosticInfo &DI, void *MsgP) { - auto *Msg = reinterpret_cast<std::string *>(MsgP); - raw_string_ostream OS(*Msg); - DiagnosticPrinterRawOStream DP(OS); - DI.print(DP); - }; - File->Ctx.setDiagnosticHandler(DiagHandler, static_cast<void *>(&Msg)); - ErrorOr<std::unique_ptr<object::IRObjectFile>> IRObj = + Expected<std::unique_ptr<object::IRObjectFile>> IRObj = IRObjectFile::create(Object, File->Ctx); - if (!Msg.empty()) - return make_error<StringError>(Msg, inconvertibleErrorCode()); if (!IRObj) - return errorCodeToError(IRObj.getError()); + return IRObj.takeError(); File->Obj = std::move(*IRObj); - File->Ctx.setDiagnosticHandler(nullptr, nullptr); - for (const auto &C : File->Obj->getModule().getComdatSymbolTable()) { auto P = File->ComdatMap.insert(std::make_pair(&C.second, File->Comdats.size())); @@ -346,10 +333,10 @@ Error LTO::addRegularLTO(std::unique_ptr<InputFile> Input, llvm::make_unique<Module>("ld-temp.o", RegularLTO.Ctx); RegularLTO.Mover = llvm::make_unique<IRMover>(*RegularLTO.CombinedModule); } - ErrorOr<std::unique_ptr<object::IRObjectFile>> ObjOrErr = + Expected<std::unique_ptr<object::IRObjectFile>> ObjOrErr = IRObjectFile::create(Input->Obj->getMemoryBufferRef(), RegularLTO.Ctx); if (!ObjOrErr) - return errorCodeToError(ObjOrErr.getError()); + return ObjOrErr.takeError(); std::unique_ptr<object::IRObjectFile> Obj = std::move(*ObjOrErr); Module &M = Obj->getModule(); @@ -571,9 +558,10 @@ public: MapVector<StringRef, MemoryBufferRef> &ModuleMap) { auto RunThinBackend = [&](AddStreamFn AddStream) { LTOLLVMContext BackendContext(Conf); - ErrorOr<std::unique_ptr<Module>> MOrErr = + Expected<std::unique_ptr<Module>> MOrErr = parseBitcodeFile(MBRef, BackendContext); - assert(MOrErr && "Unable to load module in thread?"); + if (!MOrErr) + return MOrErr.takeError(); return thinBackend(Conf, Task, AddStream, **MOrErr, CombinedIndex, ImportList, DefinedGlobals, ModuleMap); |