Skip to content

Commit

Permalink
Pass a && to getLazyBitcodeModule.
Browse files Browse the repository at this point in the history
This forces callers to use std::move when calling it. It is somewhat odd to have
code with std::move that doesn't always move, but it is also odd to have code
without std::move that sometimes moves.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217049 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
espindola committed Sep 3, 2014
1 parent 38a4f3b commit 6d66a1c
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 12 deletions.
6 changes: 3 additions & 3 deletions include/llvm/Bitcode/ReaderWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ namespace llvm {
class raw_ostream;

/// Read the header of the specified bitcode buffer and prepare for lazy
/// deserialization of function bodies. If successful, this takes ownership
/// of 'buffer. On error, this *does not* take ownership of Buffer.
ErrorOr<Module *> getLazyBitcodeModule(std::unique_ptr<MemoryBuffer> &Buffer,
/// deserialization of function bodies. If successful, this moves Buffer. On
/// error, this *does not* move Buffer.
ErrorOr<Module *> getLazyBitcodeModule(std::unique_ptr<MemoryBuffer> &&Buffer,
LLVMContext &Context);

/// getStreamedBitcodeModule - Read the header of the specified stream
Expand Down
2 changes: 1 addition & 1 deletion lib/Bitcode/Reader/BitReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ LLVMBool LLVMGetBitcodeModuleInContext(LLVMContextRef ContextRef,
std::unique_ptr<MemoryBuffer> Owner(unwrap(MemBuf));

ErrorOr<Module *> ModuleOrErr =
getLazyBitcodeModule(Owner, *unwrap(ContextRef));
getLazyBitcodeModule(std::move(Owner), *unwrap(ContextRef));
Owner.release();

if (std::error_code EC = ModuleOrErr.getError()) {
Expand Down
9 changes: 5 additions & 4 deletions lib/Bitcode/Reader/BitcodeReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3520,7 +3520,7 @@ 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(std::unique_ptr<MemoryBuffer> &Buffer,
getLazyBitcodeModuleImpl(std::unique_ptr<MemoryBuffer> &&Buffer,
LLVMContext &Context, bool WillMaterializeAll) {
Module *M = new Module(Buffer->getBufferIdentifier(), Context);
BitcodeReader *R = new BitcodeReader(Buffer.get(), Context);
Expand All @@ -3545,9 +3545,9 @@ getLazyBitcodeModuleImpl(std::unique_ptr<MemoryBuffer> &Buffer,
}

ErrorOr<Module *>
llvm::getLazyBitcodeModule(std::unique_ptr<MemoryBuffer> &Buffer,
llvm::getLazyBitcodeModule(std::unique_ptr<MemoryBuffer> &&Buffer,
LLVMContext &Context) {
return getLazyBitcodeModuleImpl(Buffer, Context, false);
return getLazyBitcodeModuleImpl(std::move(Buffer), Context, false);
}

Module *llvm::getStreamedBitcodeModule(const std::string &name,
Expand All @@ -3569,7 +3569,8 @@ 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, Context, true);
ErrorOr<Module *> ModuleOrErr =
getLazyBitcodeModuleImpl(std::move(Buf), Context, true);
if (!ModuleOrErr)
return ModuleOrErr;
Module *M = ModuleOrErr.get();
Expand Down
3 changes: 2 additions & 1 deletion lib/IRReader/IRReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ getLazyIRModule(std::unique_ptr<MemoryBuffer> Buffer, SMDiagnostic &Err,
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(std::move(Buffer), Context);
if (std::error_code EC = ModuleOrErr.getError()) {
Err = SMDiagnostic(Buffer->getBufferIdentifier(), SourceMgr::DK_Error,
EC.message());
Expand Down
2 changes: 1 addition & 1 deletion lib/Object/IRObjectFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ llvm::object::IRObjectFile::createIRObjectFile(MemoryBufferRef Object,

std::unique_ptr<MemoryBuffer> Buff(MemoryBuffer::getMemBuffer(Object, false));

ErrorOr<Module *> MOrErr = getLazyBitcodeModule(Buff, Context);
ErrorOr<Module *> MOrErr = getLazyBitcodeModule(std::move(Buff), Context);
if (std::error_code EC = MOrErr.getError())
return EC;

Expand Down
2 changes: 1 addition & 1 deletion tools/gold/gold-plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ getModuleForFile(LLVMContext &Context, claimed_file &F, raw_fd_ostream *ApiFile,
if (release_input_file(F.handle) != LDPS_OK)
message(LDPL_FATAL, "Failed to release file information");

ErrorOr<Module *> MOrErr = getLazyBitcodeModule(Buffer, Context);
ErrorOr<Module *> MOrErr = getLazyBitcodeModule(std::move(Buffer), Context);

if (std::error_code EC = MOrErr.getError())
message(LDPL_FATAL, "Could not read bitcode from file : %s",
Expand Down
3 changes: 2 additions & 1 deletion unittests/Bitcode/BitReaderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ static std::unique_ptr<Module> getLazyModuleFromAssembly(LLVMContext &Context,
writeModuleToBuffer(parseAssembly(Assembly), Mem);
std::unique_ptr<MemoryBuffer> Buffer =
MemoryBuffer::getMemBuffer(Mem.str(), "test", false);
ErrorOr<Module *> ModuleOrErr = getLazyBitcodeModule(Buffer, Context);
ErrorOr<Module *> ModuleOrErr =
getLazyBitcodeModule(std::move(Buffer), Context);
return std::unique_ptr<Module>(ModuleOrErr.get());
}

Expand Down

0 comments on commit 6d66a1c

Please sign in to comment.