Update getLazyBitcodeModule to use ErrorOr for error handling.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199125 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola
2014-01-13 18:31:04 +00:00
parent 36713c2c0a
commit 99c7fec2c9
7 changed files with 41 additions and 34 deletions

View File

@@ -3274,18 +3274,14 @@ const error_category &BitcodeReader::BitcodeErrorCategory() {
/// getLazyBitcodeModule - lazy function-at-a-time loading from a file.
///
Module *llvm::getLazyBitcodeModule(MemoryBuffer *Buffer,
LLVMContext& Context,
std::string *ErrMsg) {
ErrorOr<Module *> llvm::getLazyBitcodeModule(MemoryBuffer *Buffer,
LLVMContext &Context) {
Module *M = new Module(Buffer->getBufferIdentifier(), Context);
BitcodeReader *R = new BitcodeReader(Buffer, Context);
M->setMaterializer(R);
if (error_code EC = R->ParseBitcodeInto(M)) {
if (ErrMsg)
*ErrMsg = EC.message();
delete M; // Also deletes R.
return 0;
return EC;
}
// Have the BitcodeReader dtor delete 'Buffer'.
R->setBufferOwned(true);
@@ -3317,8 +3313,13 @@ Module *llvm::getStreamedBitcodeModule(const std::string &name,
/// If an error occurs, return null and fill in *ErrMsg if non-null.
Module *llvm::ParseBitcodeFile(MemoryBuffer *Buffer, LLVMContext& Context,
std::string *ErrMsg){
Module *M = getLazyBitcodeModule(Buffer, Context, ErrMsg);
if (!M) return 0;
ErrorOr<Module *> ModuleOrErr = getLazyBitcodeModule(Buffer, Context);
if (error_code EC = ModuleOrErr.getError()) {
if (ErrMsg)
*ErrMsg = EC.message();
return 0;
}
Module *M = ModuleOrErr.get();
// Don't let the BitcodeReader dtor delete 'Buffer', regardless of whether
// there was an error.