summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Bitcode/Reader
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2015-06-16 22:27:55 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2015-06-16 22:27:55 +0000
commitdcd1dca275595bfabbd4abfdf0df6419f0f95a53 (patch)
tree8d97c3fa45635159b605f80e9a6ccb7272625eb5 /llvm/lib/Bitcode/Reader
parent5293379374f46f670305a75dd3df667f04292dc9 (diff)
downloadbcm5719-llvm-dcd1dca275595bfabbd4abfdf0df6419f0f95a53.tar.gz
bcm5719-llvm-dcd1dca275595bfabbd4abfdf0df6419f0f95a53.zip
Return a unique_ptr from getLazyBitcodeModule and parseBitcodeFile. NFC.
llvm-svn: 239858
Diffstat (limited to 'llvm/lib/Bitcode/Reader')
-rw-r--r--llvm/lib/Bitcode/Reader/BitReader.cpp8
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp30
2 files changed, 17 insertions, 21 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitReader.cpp b/llvm/lib/Bitcode/Reader/BitReader.cpp
index 868fbf010db..289c76e85b4 100644
--- a/llvm/lib/Bitcode/Reader/BitReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitReader.cpp
@@ -39,7 +39,7 @@ LLVMBool LLVMParseBitcodeInContext(LLVMContextRef ContextRef,
raw_string_ostream Stream(Message);
DiagnosticPrinterRawOStream DP(Stream);
- ErrorOr<Module *> ModuleOrErr = parseBitcodeFile(
+ ErrorOr<std::unique_ptr<Module>> ModuleOrErr = parseBitcodeFile(
Buf, Ctx, [&](const DiagnosticInfo &DI) { DI.print(DP); });
if (ModuleOrErr.getError()) {
if (OutMessage) {
@@ -50,7 +50,7 @@ LLVMBool LLVMParseBitcodeInContext(LLVMContextRef ContextRef,
return 1;
}
- *OutModule = wrap(ModuleOrErr.get());
+ *OutModule = wrap(ModuleOrErr.get().release());
return 0;
}
@@ -64,7 +64,7 @@ LLVMBool LLVMGetBitcodeModuleInContext(LLVMContextRef ContextRef,
std::string Message;
std::unique_ptr<MemoryBuffer> Owner(unwrap(MemBuf));
- ErrorOr<Module *> ModuleOrErr =
+ ErrorOr<std::unique_ptr<Module>> ModuleOrErr =
getLazyBitcodeModule(std::move(Owner), *unwrap(ContextRef));
Owner.release();
@@ -75,7 +75,7 @@ LLVMBool LLVMGetBitcodeModuleInContext(LLVMContextRef ContextRef,
return 1;
}
- *OutM = wrap(ModuleOrErr.get());
+ *OutM = wrap(ModuleOrErr.get().release());
return 0;
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index a4488ae05ab..d012da61c4d 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -4600,24 +4600,24 @@ 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 *>
+static ErrorOr<std::unique_ptr<Module>>
getLazyBitcodeModuleImpl(std::unique_ptr<MemoryBuffer> &&Buffer,
LLVMContext &Context, bool WillMaterializeAll,
DiagnosticHandlerFunction DiagnosticHandler,
bool ShouldLazyLoadMetadata = false) {
- Module *M = new Module(Buffer->getBufferIdentifier(), Context);
+ std::unique_ptr<Module> M =
+ make_unique<Module>(Buffer->getBufferIdentifier(), Context);
BitcodeReader *R =
new BitcodeReader(Buffer.get(), Context, DiagnosticHandler);
M->setMaterializer(R);
auto cleanupOnError = [&](std::error_code EC) {
R->releaseBuffer(); // Never take ownership on error.
- delete M; // Also deletes R.
return EC;
};
// Delay parsing Metadata if ShouldLazyLoadMetadata is true.
- if (std::error_code EC = R->parseBitcodeInto(M, ShouldLazyLoadMetadata))
+ if (std::error_code EC = R->parseBitcodeInto(M.get(), ShouldLazyLoadMetadata))
return cleanupOnError(EC);
if (!WillMaterializeAll)
@@ -4626,14 +4626,12 @@ getLazyBitcodeModuleImpl(std::unique_ptr<MemoryBuffer> &&Buffer,
return cleanupOnError(EC);
Buffer.release(); // The BitcodeReader owns it now.
- return M;
+ return std::move(M);
}
-ErrorOr<Module *>
-llvm::getLazyBitcodeModule(std::unique_ptr<MemoryBuffer> &&Buffer,
- LLVMContext &Context,
- DiagnosticHandlerFunction DiagnosticHandler,
- bool ShouldLazyLoadMetadata) {
+ErrorOr<std::unique_ptr<Module>> llvm::getLazyBitcodeModule(
+ std::unique_ptr<MemoryBuffer> &&Buffer, LLVMContext &Context,
+ DiagnosticHandlerFunction DiagnosticHandler, bool ShouldLazyLoadMetadata) {
return getLazyBitcodeModuleImpl(std::move(Buffer), Context, false,
DiagnosticHandler, ShouldLazyLoadMetadata);
}
@@ -4650,25 +4648,23 @@ llvm::getStreamedBitcodeModule(StringRef Name, DataStreamer *Streamer,
return std::move(M);
}
-ErrorOr<Module *>
+ErrorOr<std::unique_ptr<Module>>
llvm::parseBitcodeFile(MemoryBufferRef Buffer, LLVMContext &Context,
DiagnosticHandlerFunction DiagnosticHandler) {
std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(Buffer, false);
- ErrorOr<Module *> ModuleOrErr = getLazyBitcodeModuleImpl(
+ ErrorOr<std::unique_ptr<Module>> ModuleOrErr = getLazyBitcodeModuleImpl(
std::move(Buf), Context, true, DiagnosticHandler);
if (!ModuleOrErr)
return ModuleOrErr;
- Module *M = ModuleOrErr.get();
+ std::unique_ptr<Module> &M = ModuleOrErr.get();
// Read in the entire module, and destroy the BitcodeReader.
- if (std::error_code EC = M->materializeAllPermanently()) {
- delete M;
+ if (std::error_code EC = M->materializeAllPermanently())
return EC;
- }
// 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.
- return M;
+ return std::move(M);
}
std::string
OpenPOWER on IntegriCloud