summaryrefslogtreecommitdiff
path: root/lib/IRReader
diff options
context:
space:
mode:
authorAlp Toker <alp@nuanti.com>2014-06-27 04:33:58 +0000
committerAlp Toker <alp@nuanti.com>2014-06-27 04:33:58 +0000
commitd0996e5b33ede018999044f3c5f05e72540d97c4 (patch)
treec78a4ab783abfeb12368e4dfbf0f3b122ad89fde /lib/IRReader
parent493512898faad01ed17c988f422a644e6fe83264 (diff)
ParseIR: don't take ownership of the MemoryBuffer
clang was needlessly duplicating whole memory buffer contents in an attempt to satisfy unclear ownership semantics. Let's just hide internal LLVM quirks and present a simple non-owning interface. The public C API preserves previous behaviour for stability. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211861 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/IRReader')
-rw-r--r--lib/IRReader/IRReader.cpp17
1 files changed, 10 insertions, 7 deletions
diff --git a/lib/IRReader/IRReader.cpp b/lib/IRReader/IRReader.cpp
index 01aa074abad..2bbe0753320 100644
--- a/lib/IRReader/IRReader.cpp
+++ b/lib/IRReader/IRReader.cpp
@@ -39,7 +39,7 @@ Module *llvm::getLazyIRModule(MemoryBuffer *Buffer, SMDiagnostic &Err,
if (std::error_code EC = ModuleOrErr.getError()) {
Err = SMDiagnostic(Buffer->getBufferIdentifier(), SourceMgr::DK_Error,
EC.message());
- // ParseBitcodeFile does not take ownership of the Buffer in the
+ // getLazyBitcodeModule does not take ownership of the Buffer in the
// case of an error.
delete Buffer;
return nullptr;
@@ -62,13 +62,14 @@ Module *llvm::getLazyIRFileModule(const std::string &Filename, SMDiagnostic &Err
return getLazyIRModule(File.release(), Err, Context);
}
-Module *llvm::ParseIR(MemoryBuffer *Buffer, SMDiagnostic &Err,
+Module *llvm::ParseIR(const MemoryBuffer *Buffer, SMDiagnostic &Err,
LLVMContext &Context) {
NamedRegionTimer T(TimeIRParsingName, TimeIRParsingGroupName,
TimePassesIsEnabled);
if (isBitcode((const unsigned char *)Buffer->getBufferStart(),
(const unsigned char *)Buffer->getBufferEnd())) {
- ErrorOr<Module *> ModuleOrErr = parseBitcodeFile(Buffer, Context);
+ ErrorOr<Module *> ModuleOrErr =
+ parseBitcodeFile(const_cast<MemoryBuffer *>(Buffer), Context);
Module *M = nullptr;
if (std::error_code EC = ModuleOrErr.getError())
Err = SMDiagnostic(Buffer->getBufferIdentifier(), SourceMgr::DK_Error,
@@ -76,11 +77,12 @@ Module *llvm::ParseIR(MemoryBuffer *Buffer, SMDiagnostic &Err,
else
M = ModuleOrErr.get();
// parseBitcodeFile does not take ownership of the Buffer.
- delete Buffer;
return M;
}
- return ParseAssembly(Buffer, nullptr, Err, Context);
+ return ParseAssembly(MemoryBuffer::getMemBuffer(
+ Buffer->getBuffer(), Buffer->getBufferIdentifier()),
+ nullptr, Err, Context);
}
Module *llvm::ParseIRFile(const std::string &Filename, SMDiagnostic &Err,
@@ -92,7 +94,7 @@ Module *llvm::ParseIRFile(const std::string &Filename, SMDiagnostic &Err,
return nullptr;
}
- return ParseIR(File.release(), Err, Context);
+ return ParseIR(File.get(), Err, Context);
}
//===----------------------------------------------------------------------===//
@@ -104,7 +106,8 @@ LLVMBool LLVMParseIRInContext(LLVMContextRef ContextRef,
char **OutMessage) {
SMDiagnostic Diag;
- *OutM = wrap(ParseIR(unwrap(MemBuf), Diag, *unwrap(ContextRef)));
+ std::unique_ptr<MemoryBuffer> MB(unwrap(MemBuf));
+ *OutM = wrap(ParseIR(MB.get(), Diag, *unwrap(ContextRef)));
if(!*OutM) {
if (OutMessage) {