Bitcode: Change module reader functions to return an llvm::Expected.

Differential Revision: https://reviews.llvm.org/D26562

llvm-svn: 286752
This commit is contained in:
Peter Collingbourne 2016-11-13 07:00:17 +00:00
parent 8dff03911c
commit d9445c49ad
18 changed files with 106 additions and 125 deletions

View File

@ -3012,7 +3012,8 @@ void CGOpenMPRuntime::loadOffloadInfoMetadata() {
return;
llvm::LLVMContext C;
auto ME = llvm::parseBitcodeFile(Buf.get()->getMemBufferRef(), C);
auto ME = expectedToErrorOrAndEmitErrors(
C, llvm::parseBitcodeFile(Buf.get()->getMemBufferRef(), C));
if (ME.getError())
return;

View File

@ -771,11 +771,13 @@ CodeGenAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
return nullptr;
}
ErrorOr<std::unique_ptr<llvm::Module>> ModuleOrErr =
Expected<std::unique_ptr<llvm::Module>> ModuleOrErr =
getOwningLazyBitcodeModule(std::move(*BCBuf), *VMContext);
if (std::error_code EC = ModuleOrErr.getError()) {
CI.getDiagnostics().Report(diag::err_cannot_open_file) << LinkBCFile
<< EC.message();
if (!ModuleOrErr) {
handleAllErrors(ModuleOrErr.takeError(), [&](ErrorInfoBase &EIB) {
CI.getDiagnostics().Report(diag::err_cannot_open_file)
<< LinkBCFile << EIB.message();
});
LinkModules.clear();
return nullptr;
}

View File

@ -43,14 +43,14 @@ namespace llvm {
/// Read the header of the specified bitcode buffer and prepare for lazy
/// deserialization of function bodies. If ShouldLazyLoadMetadata is true,
/// lazily load metadata as well.
ErrorOr<std::unique_ptr<Module>>
Expected<std::unique_ptr<Module>>
getLazyBitcodeModule(MemoryBufferRef Buffer, LLVMContext &Context,
bool ShouldLazyLoadMetadata = false);
/// Like getLazyBitcodeModule, except that the module takes ownership of
/// the memory buffer if successful. If successful, this moves Buffer. On
/// error, this *does not* move Buffer.
ErrorOr<std::unique_ptr<Module>>
Expected<std::unique_ptr<Module>>
getOwningLazyBitcodeModule(std::unique_ptr<MemoryBuffer> &&Buffer,
LLVMContext &Context,
bool ShouldLazyLoadMetadata = false);
@ -70,8 +70,8 @@ namespace llvm {
Expected<std::string> getBitcodeProducerString(MemoryBufferRef Buffer);
/// Read the specified bitcode file, returning the module.
ErrorOr<std::unique_ptr<Module>> parseBitcodeFile(MemoryBufferRef Buffer,
LLVMContext &Context);
Expected<std::unique_ptr<Module>> parseBitcodeFile(MemoryBufferRef Buffer,
LLVMContext &Context);
/// Check if the given bitcode buffer contains a summary block.
Expected<bool> hasGlobalValueSummary(MemoryBufferRef Buffer);

View File

@ -75,8 +75,8 @@ public:
static ErrorOr<MemoryBufferRef>
findBitcodeInMemBuffer(MemoryBufferRef Object);
static ErrorOr<std::unique_ptr<IRObjectFile>> create(MemoryBufferRef Object,
LLVMContext &Context);
static Expected<std::unique_ptr<IRObjectFile>> create(MemoryBufferRef Object,
LLVMContext &Context);
};
}
}

View File

@ -44,10 +44,12 @@ public:
/// The set contains an entry for every global value the module exports.
typedef std::unordered_set<GlobalValue::GUID> ExportSetTy;
/// A function of this type is used to load modules referenced by the index.
typedef std::function<Expected<std::unique_ptr<Module>>(StringRef Identifier)>
ModuleLoaderTy;
/// Create a Function Importer.
FunctionImporter(
const ModuleSummaryIndex &Index,
std::function<std::unique_ptr<Module>(StringRef Identifier)> ModuleLoader)
FunctionImporter(const ModuleSummaryIndex &Index, ModuleLoaderTy ModuleLoader)
: Index(Index), ModuleLoader(std::move(ModuleLoader)) {}
/// Import functions in Module \p M based on the supplied import list.
@ -63,7 +65,7 @@ private:
const ModuleSummaryIndex &Index;
/// Factory function to load a Module for a given identifier
std::function<std::unique_ptr<Module>(StringRef Identifier)> ModuleLoader;
ModuleLoaderTy ModuleLoader;
};
/// The function importing pass

View File

@ -34,13 +34,6 @@ LLVMBool LLVMParseBitcode2(LLVMMemoryBufferRef MemBuf,
return LLVMParseBitcodeInContext2(LLVMGetGlobalContext(), MemBuf, OutModule);
}
static void diagnosticHandler(const DiagnosticInfo &DI, void *C) {
auto *Message = reinterpret_cast<std::string *>(C);
raw_string_ostream Stream(*Message);
DiagnosticPrinterRawOStream DP(Stream);
DI.print(DP);
}
LLVMBool LLVMParseBitcodeInContext(LLVMContextRef ContextRef,
LLVMMemoryBufferRef MemBuf,
LLVMModuleRef *OutModule,
@ -48,17 +41,12 @@ LLVMBool LLVMParseBitcodeInContext(LLVMContextRef ContextRef,
MemoryBufferRef Buf = unwrap(MemBuf)->getMemBufferRef();
LLVMContext &Ctx = *unwrap(ContextRef);
LLVMContext::DiagnosticHandlerTy OldDiagnosticHandler =
Ctx.getDiagnosticHandler();
void *OldDiagnosticContext = Ctx.getDiagnosticContext();
std::string Message;
Ctx.setDiagnosticHandler(diagnosticHandler, &Message, true);
ErrorOr<std::unique_ptr<Module>> ModuleOrErr = parseBitcodeFile(Buf, Ctx);
Ctx.setDiagnosticHandler(OldDiagnosticHandler, OldDiagnosticContext, true);
if (ModuleOrErr.getError()) {
Expected<std::unique_ptr<Module>> ModuleOrErr = parseBitcodeFile(Buf, Ctx);
if (Error Err = ModuleOrErr.takeError()) {
std::string Message;
handleAllErrors(std::move(Err), [&](ErrorInfoBase &EIB) {
Message = EIB.message();
});
if (OutMessage)
*OutMessage = strdup(Message.c_str());
*OutModule = wrap((Module *)nullptr);
@ -75,7 +63,8 @@ LLVMBool LLVMParseBitcodeInContext2(LLVMContextRef ContextRef,
MemoryBufferRef Buf = unwrap(MemBuf)->getMemBufferRef();
LLVMContext &Ctx = *unwrap(ContextRef);
ErrorOr<std::unique_ptr<Module>> ModuleOrErr = parseBitcodeFile(Buf, Ctx);
ErrorOr<std::unique_ptr<Module>> ModuleOrErr =
expectedToErrorOrAndEmitErrors(Ctx, parseBitcodeFile(Buf, Ctx));
if (ModuleOrErr.getError()) {
*OutModule = wrap((Module *)nullptr);
return 1;
@ -92,23 +81,19 @@ LLVMBool LLVMGetBitcodeModuleInContext(LLVMContextRef ContextRef,
LLVMMemoryBufferRef MemBuf,
LLVMModuleRef *OutM, char **OutMessage) {
LLVMContext &Ctx = *unwrap(ContextRef);
LLVMContext::DiagnosticHandlerTy OldDiagnosticHandler =
Ctx.getDiagnosticHandler();
void *OldDiagnosticContext = Ctx.getDiagnosticContext();
std::string Message;
Ctx.setDiagnosticHandler(diagnosticHandler, &Message, true);
std::unique_ptr<MemoryBuffer> Owner(unwrap(MemBuf));
ErrorOr<std::unique_ptr<Module>> ModuleOrErr =
Expected<std::unique_ptr<Module>> ModuleOrErr =
getOwningLazyBitcodeModule(std::move(Owner), Ctx);
Owner.release();
Ctx.setDiagnosticHandler(OldDiagnosticHandler, OldDiagnosticContext, true);
if (ModuleOrErr.getError()) {
*OutM = wrap((Module *)nullptr);
if (Error Err = ModuleOrErr.takeError()) {
std::string Message;
handleAllErrors(std::move(Err), [&](ErrorInfoBase &EIB) {
Message = EIB.message();
});
if (OutMessage)
*OutMessage = strdup(Message.c_str());
*OutM = wrap((Module *)nullptr);
return 1;
}
@ -123,8 +108,8 @@ LLVMBool LLVMGetBitcodeModuleInContext2(LLVMContextRef ContextRef,
LLVMContext &Ctx = *unwrap(ContextRef);
std::unique_ptr<MemoryBuffer> Owner(unwrap(MemBuf));
ErrorOr<std::unique_ptr<Module>> ModuleOrErr =
getOwningLazyBitcodeModule(std::move(Owner), Ctx);
ErrorOr<std::unique_ptr<Module>> ModuleOrErr = expectedToErrorOrAndEmitErrors(
Ctx, getOwningLazyBitcodeModule(std::move(Owner), Ctx));
Owner.release();
if (ModuleOrErr.getError()) {

View File

@ -6571,13 +6571,13 @@ const std::error_category &llvm::BitcodeErrorCategory() {
///
/// \param[in] MaterializeAll Set to \c true if we should materialize
/// everything.
static ErrorOr<std::unique_ptr<Module>>
static Expected<std::unique_ptr<Module>>
getLazyBitcodeModuleImpl(MemoryBufferRef Buffer, LLVMContext &Context,
bool MaterializeAll,
bool ShouldLazyLoadMetadata = false) {
Expected<BitstreamCursor> StreamOrErr = initStream(Buffer);
if (!StreamOrErr)
return errorToErrorCodeAndEmitErrors(Context, StreamOrErr.takeError());
return StreamOrErr.takeError();
BitcodeReader *R = new BitcodeReader(std::move(*StreamOrErr), Context);
@ -6587,28 +6587,28 @@ getLazyBitcodeModuleImpl(MemoryBufferRef Buffer, LLVMContext &Context,
// Delay parsing Metadata if ShouldLazyLoadMetadata is true.
if (Error Err = R->parseBitcodeInto(M.get(), ShouldLazyLoadMetadata))
return errorToErrorCodeAndEmitErrors(Context, std::move(Err));
return std::move(Err);
if (MaterializeAll) {
// Read in the entire module, and destroy the BitcodeReader.
if (Error Err = M->materializeAll())
return errorToErrorCodeAndEmitErrors(Context, std::move(Err));
return std::move(Err);
} else {
// Resolve forward references from blockaddresses.
if (Error Err = R->materializeForwardReferencedFunctions())
return errorToErrorCodeAndEmitErrors(Context, std::move(Err));
return std::move(Err);
}
return std::move(M);
}
ErrorOr<std::unique_ptr<Module>>
Expected<std::unique_ptr<Module>>
llvm::getLazyBitcodeModule(MemoryBufferRef Buffer,
LLVMContext &Context, bool ShouldLazyLoadMetadata) {
return getLazyBitcodeModuleImpl(Buffer, Context, false,
ShouldLazyLoadMetadata);
}
ErrorOr<std::unique_ptr<Module>>
Expected<std::unique_ptr<Module>>
llvm::getOwningLazyBitcodeModule(std::unique_ptr<MemoryBuffer> &&Buffer,
LLVMContext &Context,
bool ShouldLazyLoadMetadata) {
@ -6618,8 +6618,8 @@ llvm::getOwningLazyBitcodeModule(std::unique_ptr<MemoryBuffer> &&Buffer,
return MOrErr;
}
ErrorOr<std::unique_ptr<Module>> llvm::parseBitcodeFile(MemoryBufferRef Buffer,
LLVMContext &Context) {
Expected<std::unique_ptr<Module>> llvm::parseBitcodeFile(MemoryBufferRef Buffer,
LLVMContext &Context) {
return getLazyBitcodeModuleImpl(Buffer, Context, true);
// TODO: Restore the use-lists to the in-memory state when the bitcode was
// written. We must defer until the Module has been fully materialized.

View File

@ -79,7 +79,7 @@ std::unique_ptr<Module> llvm::splitCodeGen(
CodegenThreadPool.async(
[TMFactory, FileType, ThreadOS](const SmallString<0> &BC) {
LLVMContext Ctx;
ErrorOr<std::unique_ptr<Module>> MOrErr = parseBitcodeFile(
Expected<std::unique_ptr<Module>> MOrErr = parseBitcodeFile(
MemoryBufferRef(StringRef(BC.data(), BC.size()),
"<split-module>"),
Ctx);

View File

@ -34,11 +34,13 @@ getLazyIRModule(std::unique_ptr<MemoryBuffer> Buffer, SMDiagnostic &Err,
LLVMContext &Context, bool ShouldLazyLoadMetadata) {
if (isBitcode((const unsigned char *)Buffer->getBufferStart(),
(const unsigned char *)Buffer->getBufferEnd())) {
ErrorOr<std::unique_ptr<Module>> ModuleOrErr = getOwningLazyBitcodeModule(
Expected<std::unique_ptr<Module>> ModuleOrErr = getOwningLazyBitcodeModule(
std::move(Buffer), Context, ShouldLazyLoadMetadata);
if (std::error_code EC = ModuleOrErr.getError()) {
Err = SMDiagnostic(Buffer->getBufferIdentifier(), SourceMgr::DK_Error,
EC.message());
if (Error E = ModuleOrErr.takeError()) {
handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
Err = SMDiagnostic(Buffer->getBufferIdentifier(), SourceMgr::DK_Error,
EIB.message());
});
return nullptr;
}
return std::move(ModuleOrErr.get());
@ -69,11 +71,13 @@ std::unique_ptr<Module> llvm::parseIR(MemoryBufferRef Buffer, SMDiagnostic &Err,
TimePassesIsEnabled);
if (isBitcode((const unsigned char *)Buffer.getBufferStart(),
(const unsigned char *)Buffer.getBufferEnd())) {
ErrorOr<std::unique_ptr<Module>> ModuleOrErr =
Expected<std::unique_ptr<Module>> ModuleOrErr =
parseBitcodeFile(Buffer, Context);
if (std::error_code EC = ModuleOrErr.getError()) {
Err = SMDiagnostic(Buffer.getBufferIdentifier(), SourceMgr::DK_Error,
EC.message());
if (Error E = ModuleOrErr.takeError()) {
handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
Err = SMDiagnostic(Buffer.getBufferIdentifier(), SourceMgr::DK_Error,
EIB.message());
});
return nullptr;
}
return std::move(ModuleOrErr.get());

View File

@ -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);

View File

@ -237,7 +237,7 @@ void splitCodeGen(Config &C, TargetMachine *TM, AddStreamFn AddStream,
CodegenThreadPool.async(
[&](const SmallString<0> &BC, unsigned ThreadId) {
LTOLLVMContext Ctx(C);
ErrorOr<std::unique_ptr<Module>> MOrErr = parseBitcodeFile(
Expected<std::unique_ptr<Module>> MOrErr = parseBitcodeFile(
MemoryBufferRef(StringRef(BC.data(), BC.size()), "ld-temp.o"),
Ctx);
if (!MOrErr)
@ -353,10 +353,8 @@ Error lto::thinBackend(Config &Conf, unsigned Task, AddStreamFn AddStream,
auto ModuleLoader = [&](StringRef Identifier) {
assert(Mod.getContext().isODRUniquingDebugTypes() &&
"ODR Type uniquing should be enabled on the context");
return std::move(getLazyBitcodeModule(ModuleMap[Identifier],
Mod.getContext(),
/*ShouldLazyLoadMetadata=*/true)
.get());
return getLazyBitcodeModule(ModuleMap[Identifier], Mod.getContext(),
/*ShouldLazyLoadMetadata=*/true);
};
FunctionImporter Importer(CombinedIndex, ModuleLoader);

View File

@ -184,18 +184,14 @@ parseBitcodeFileImpl(MemoryBufferRef Buffer, LLVMContext &Context,
if (!ShouldBeLazy) {
// Parse the full file.
ErrorOr<std::unique_ptr<Module>> M = parseBitcodeFile(*MBOrErr, Context);
if (std::error_code EC = M.getError())
return EC;
return std::move(*M);
return expectedToErrorOrAndEmitErrors(Context,
parseBitcodeFile(*MBOrErr, Context));
}
// Parse lazily.
ErrorOr<std::unique_ptr<Module>> M =
getLazyBitcodeModule(*MBOrErr, Context, true /*ShouldLazyLoadMetadata*/);
if (std::error_code EC = M.getError())
return EC;
return std::move(*M);
return expectedToErrorOrAndEmitErrors(
Context,
getLazyBitcodeModule(*MBOrErr, Context, true /*ShouldLazyLoadMetadata*/));
}
ErrorOr<std::unique_ptr<LTOModule>>

View File

@ -310,18 +310,18 @@ ErrorOr<MemoryBufferRef> IRObjectFile::findBitcodeInMemBuffer(MemoryBufferRef Ob
}
}
ErrorOr<std::unique_ptr<IRObjectFile>>
Expected<std::unique_ptr<IRObjectFile>>
llvm::object::IRObjectFile::create(MemoryBufferRef Object,
LLVMContext &Context) {
ErrorOr<MemoryBufferRef> BCOrErr = findBitcodeInMemBuffer(Object);
if (!BCOrErr)
return BCOrErr.getError();
return errorCodeToError(BCOrErr.getError());
ErrorOr<std::unique_ptr<Module>> MOrErr =
Expected<std::unique_ptr<Module>> MOrErr =
getLazyBitcodeModule(*BCOrErr, Context,
/*ShouldLazyLoadMetadata*/ true);
if (std::error_code EC = MOrErr.getError())
return EC;
if (!MOrErr)
return MOrErr.takeError();
std::unique_ptr<Module> &M = MOrErr.get();
return llvm::make_unique<IRObjectFile>(BCOrErr.get(), std::move(M));

View File

@ -35,7 +35,7 @@ Expected<std::unique_ptr<SymbolicFile>> SymbolicFile::createSymbolicFile(
switch (Type) {
case sys::fs::file_magic::bitcode:
if (Context)
return errorOrToExpected(IRObjectFile::create(Object, *Context));
return IRObjectFile::create(Object, *Context);
LLVM_FALLTHROUGH;
case sys::fs::file_magic::unknown:
case sys::fs::file_magic::archive:
@ -73,9 +73,9 @@ Expected<std::unique_ptr<SymbolicFile>> SymbolicFile::createSymbolicFile(
if (!BCData)
return std::move(Obj);
return errorOrToExpected(IRObjectFile::create(
MemoryBufferRef(BCData->getBuffer(),
Object.getBufferIdentifier()), *Context));
return IRObjectFile::create(
MemoryBufferRef(BCData->getBuffer(), Object.getBufferIdentifier()),
*Context);
}
}
llvm_unreachable("Unexpected Binary File Type");

View File

@ -624,7 +624,10 @@ Expected<bool> FunctionImporter::importFunctions(
// Get the module for the import
const auto &FunctionsToImportPerModule = ImportList.find(Name);
assert(FunctionsToImportPerModule != ImportList.end());
std::unique_ptr<Module> SrcModule = ModuleLoader(Name);
Expected<std::unique_ptr<Module>> SrcModuleOrErr = ModuleLoader(Name);
if (!SrcModuleOrErr)
return SrcModuleOrErr.takeError();
std::unique_ptr<Module> SrcModule = std::move(*SrcModuleOrErr);
assert(&DestModule.getContext() == &SrcModule->getContext() &&
"Context mismatch");

View File

@ -142,9 +142,9 @@ static ExitOnError ExitOnErr;
static std::unique_ptr<Module> openInputFile(LLVMContext &Context) {
std::unique_ptr<MemoryBuffer> MB =
ExitOnErr(errorOrToExpected(MemoryBuffer::getFileOrSTDIN(InputFilename)));
std::unique_ptr<Module> M = ExitOnErr(errorOrToExpected(
getOwningLazyBitcodeModule(std::move(MB), Context,
/*ShouldLazyLoadMetadata=*/true)));
std::unique_ptr<Module> M =
ExitOnErr(getOwningLazyBitcodeModule(std::move(MB), Context,
/*ShouldLazyLoadMetadata=*/true));
if (MaterializeMetadata)
ExitOnErr(M->materializeMetadata());
else

View File

@ -160,11 +160,11 @@ std::unique_ptr<Module> TempFile::readBitcode(LLVMContext &Context) const {
}
MemoryBuffer *Buffer = BufferOr.get().get();
ErrorOr<std::unique_ptr<Module>> ModuleOr =
Expected<std::unique_ptr<Module>> ModuleOr =
parseBitcodeFile(Buffer->getMemBufferRef(), Context);
if (!ModuleOr) {
errs() << "verify-uselistorder: error: " << ModuleOr.getError().message()
<< "\n";
logAllUnhandledErrors(ModuleOr.takeError(), errs(),
"verify-uselistorder: error: ");
return nullptr;
}
return std::move(ModuleOr.get());

View File

@ -55,8 +55,10 @@ static std::unique_ptr<Module> getLazyModuleFromAssembly(LLVMContext &Context,
SmallString<1024> &Mem,
const char *Assembly) {
writeModuleToBuffer(parseAssembly(Context, Assembly), Mem);
ErrorOr<std::unique_ptr<Module>> ModuleOrErr =
Expected<std::unique_ptr<Module>> ModuleOrErr =
getLazyBitcodeModule(MemoryBufferRef(Mem.str(), "test"), Context);
if (!ModuleOrErr)
report_fatal_error("Could not parse bitcode module");
return std::move(ModuleOrErr.get());
}