Pass a std::unique_ptr<MemoryBuffer>& to getLazyBitcodeModule.

By taking a reference we can do the ownership transfer in one place instead of
expecting every caller to do it.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216492 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola
2014-08-26 22:00:09 +00:00
parent 2292996e1a
commit fb1af0a48a
8 changed files with 22 additions and 22 deletions

View File

@@ -3519,11 +3519,11 @@ const std::error_category &llvm::BitcodeErrorCategory() {
///
/// \param[in] WillMaterializeAll Set to \c true if the caller promises to
/// materialize everything -- in particular, if this isn't truly lazy.
static ErrorOr<Module *> getLazyBitcodeModuleImpl(MemoryBuffer *Buffer,
LLVMContext &Context,
bool WillMaterializeAll) {
static ErrorOr<Module *>
getLazyBitcodeModuleImpl(std::unique_ptr<MemoryBuffer> &Buffer,
LLVMContext &Context, bool WillMaterializeAll) {
Module *M = new Module(Buffer->getBufferIdentifier(), Context);
BitcodeReader *R = new BitcodeReader(Buffer, Context);
BitcodeReader *R = new BitcodeReader(Buffer.get(), Context);
M->setMaterializer(R);
auto cleanupOnError = [&](std::error_code EC) {
@@ -3540,11 +3540,13 @@ static ErrorOr<Module *> getLazyBitcodeModuleImpl(MemoryBuffer *Buffer,
if (std::error_code EC = R->materializeForwardReferencedFunctions())
return cleanupOnError(EC);
Buffer.release(); // The BitcodeReader owns it now.
return M;
}
ErrorOr<Module *> llvm::getLazyBitcodeModule(MemoryBuffer *Buffer,
LLVMContext &Context) {
ErrorOr<Module *>
llvm::getLazyBitcodeModule(std::unique_ptr<MemoryBuffer> &Buffer,
LLVMContext &Context) {
return getLazyBitcodeModuleImpl(Buffer, Context, false);
}
@@ -3567,11 +3569,9 @@ Module *llvm::getStreamedBitcodeModule(const std::string &name,
ErrorOr<Module *> llvm::parseBitcodeFile(MemoryBufferRef Buffer,
LLVMContext &Context) {
std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(Buffer, false);
ErrorOr<Module *> ModuleOrErr =
getLazyBitcodeModuleImpl(Buf.get(), Context, true);
ErrorOr<Module *> ModuleOrErr = getLazyBitcodeModuleImpl(Buf, Context, true);
if (!ModuleOrErr)
return ModuleOrErr;
Buf.release(); // The BitcodeReader owns it now.
Module *M = ModuleOrErr.get();
// Read in the entire module, and destroy the BitcodeReader.
if (std::error_code EC = M->materializeAllPermanently()) {