mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-16 08:29:43 +00:00
getLazyIRModule always takes ownership. Make that explicit.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215851 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
40ef1799b8
commit
283c82abaa
@ -29,28 +29,27 @@ namespace llvm {
|
||||
static const char *const TimeIRParsingGroupName = "LLVM IR Parsing";
|
||||
static const char *const TimeIRParsingName = "Parse IR";
|
||||
|
||||
static Module *getLazyIRModule(MemoryBuffer *Buffer, SMDiagnostic &Err,
|
||||
LLVMContext &Context) {
|
||||
static Module *getLazyIRModule(std::unique_ptr<MemoryBuffer> Buffer,
|
||||
SMDiagnostic &Err, LLVMContext &Context) {
|
||||
if (isBitcode((const unsigned char *)Buffer->getBufferStart(),
|
||||
(const unsigned char *)Buffer->getBufferEnd())) {
|
||||
std::string ErrMsg;
|
||||
ErrorOr<Module *> ModuleOrErr = getLazyBitcodeModule(Buffer, Context);
|
||||
ErrorOr<Module *> ModuleOrErr = getLazyBitcodeModule(Buffer.get(), Context);
|
||||
if (std::error_code EC = ModuleOrErr.getError()) {
|
||||
Err = SMDiagnostic(Buffer->getBufferIdentifier(), SourceMgr::DK_Error,
|
||||
EC.message());
|
||||
// getLazyBitcodeModule does not take ownership of the Buffer in the
|
||||
// case of an error.
|
||||
delete Buffer;
|
||||
return nullptr;
|
||||
}
|
||||
// getLazyBitcodeModule takes ownership of the Buffer when successful.
|
||||
Buffer.release();
|
||||
return ModuleOrErr.get();
|
||||
}
|
||||
|
||||
return ParseAssembly(Buffer, nullptr, Err, Context);
|
||||
return ParseAssembly(Buffer.release(), nullptr, Err, Context);
|
||||
}
|
||||
|
||||
Module *llvm::getLazyIRFileModule(const std::string &Filename, SMDiagnostic &Err,
|
||||
LLVMContext &Context) {
|
||||
Module *llvm::getLazyIRFileModule(const std::string &Filename,
|
||||
SMDiagnostic &Err, LLVMContext &Context) {
|
||||
ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
|
||||
MemoryBuffer::getFileOrSTDIN(Filename);
|
||||
if (std::error_code EC = FileOrErr.getError()) {
|
||||
@ -59,7 +58,7 @@ Module *llvm::getLazyIRFileModule(const std::string &Filename, SMDiagnostic &Err
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return getLazyIRModule(FileOrErr.get().release(), Err, Context);
|
||||
return getLazyIRModule(std::move(FileOrErr.get()), Err, Context);
|
||||
}
|
||||
|
||||
Module *llvm::ParseIR(MemoryBuffer *Buffer, SMDiagnostic &Err,
|
||||
|
Loading…
Reference in New Issue
Block a user