From: Rafael Espindola Date: Wed, 3 Sep 2014 17:31:46 +0000 (+0000) Subject: Pass a && to getLazyBitcodeModule. X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=6d66a1cd2f6c47361bb9f294d7d2af1530f27914 Pass a && to getLazyBitcodeModule. 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 --- diff --git a/include/llvm/Bitcode/ReaderWriter.h b/include/llvm/Bitcode/ReaderWriter.h index 287311032f2..2e8cdc737ed 100644 --- a/include/llvm/Bitcode/ReaderWriter.h +++ b/include/llvm/Bitcode/ReaderWriter.h @@ -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 getLazyBitcodeModule(std::unique_ptr &Buffer, + /// deserialization of function bodies. If successful, this moves Buffer. On + /// error, this *does not* move Buffer. + ErrorOr getLazyBitcodeModule(std::unique_ptr &&Buffer, LLVMContext &Context); /// getStreamedBitcodeModule - Read the header of the specified stream diff --git a/lib/Bitcode/Reader/BitReader.cpp b/lib/Bitcode/Reader/BitReader.cpp index 76a7e6ae159..9b3acb5ca0a 100644 --- a/lib/Bitcode/Reader/BitReader.cpp +++ b/lib/Bitcode/Reader/BitReader.cpp @@ -54,7 +54,7 @@ LLVMBool LLVMGetBitcodeModuleInContext(LLVMContextRef ContextRef, std::unique_ptr Owner(unwrap(MemBuf)); ErrorOr ModuleOrErr = - getLazyBitcodeModule(Owner, *unwrap(ContextRef)); + getLazyBitcodeModule(std::move(Owner), *unwrap(ContextRef)); Owner.release(); if (std::error_code EC = ModuleOrErr.getError()) { diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index a614ec37cf6..84ee0b4b3a6 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -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 -getLazyBitcodeModuleImpl(std::unique_ptr &Buffer, +getLazyBitcodeModuleImpl(std::unique_ptr &&Buffer, LLVMContext &Context, bool WillMaterializeAll) { Module *M = new Module(Buffer->getBufferIdentifier(), Context); BitcodeReader *R = new BitcodeReader(Buffer.get(), Context); @@ -3545,9 +3545,9 @@ getLazyBitcodeModuleImpl(std::unique_ptr &Buffer, } ErrorOr -llvm::getLazyBitcodeModule(std::unique_ptr &Buffer, +llvm::getLazyBitcodeModule(std::unique_ptr &&Buffer, LLVMContext &Context) { - return getLazyBitcodeModuleImpl(Buffer, Context, false); + return getLazyBitcodeModuleImpl(std::move(Buffer), Context, false); } Module *llvm::getStreamedBitcodeModule(const std::string &name, @@ -3569,7 +3569,8 @@ Module *llvm::getStreamedBitcodeModule(const std::string &name, ErrorOr llvm::parseBitcodeFile(MemoryBufferRef Buffer, LLVMContext &Context) { std::unique_ptr Buf = MemoryBuffer::getMemBuffer(Buffer, false); - ErrorOr ModuleOrErr = getLazyBitcodeModuleImpl(Buf, Context, true); + ErrorOr ModuleOrErr = + getLazyBitcodeModuleImpl(std::move(Buf), Context, true); if (!ModuleOrErr) return ModuleOrErr; Module *M = ModuleOrErr.get(); diff --git a/lib/IRReader/IRReader.cpp b/lib/IRReader/IRReader.cpp index a50e3865285..342fc5b27c8 100644 --- a/lib/IRReader/IRReader.cpp +++ b/lib/IRReader/IRReader.cpp @@ -35,7 +35,8 @@ getLazyIRModule(std::unique_ptr Buffer, SMDiagnostic &Err, if (isBitcode((const unsigned char *)Buffer->getBufferStart(), (const unsigned char *)Buffer->getBufferEnd())) { std::string ErrMsg; - ErrorOr ModuleOrErr = getLazyBitcodeModule(Buffer, Context); + ErrorOr ModuleOrErr = + getLazyBitcodeModule(std::move(Buffer), Context); if (std::error_code EC = ModuleOrErr.getError()) { Err = SMDiagnostic(Buffer->getBufferIdentifier(), SourceMgr::DK_Error, EC.message()); diff --git a/lib/Object/IRObjectFile.cpp b/lib/Object/IRObjectFile.cpp index 4c050d5badb..0259b46c70c 100644 --- a/lib/Object/IRObjectFile.cpp +++ b/lib/Object/IRObjectFile.cpp @@ -270,7 +270,7 @@ llvm::object::IRObjectFile::createIRObjectFile(MemoryBufferRef Object, std::unique_ptr Buff(MemoryBuffer::getMemBuffer(Object, false)); - ErrorOr MOrErr = getLazyBitcodeModule(Buff, Context); + ErrorOr MOrErr = getLazyBitcodeModule(std::move(Buff), Context); if (std::error_code EC = MOrErr.getError()) return EC; diff --git a/tools/gold/gold-plugin.cpp b/tools/gold/gold-plugin.cpp index b08f74d5916..bdbf0263dca 100644 --- a/tools/gold/gold-plugin.cpp +++ b/tools/gold/gold-plugin.cpp @@ -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 MOrErr = getLazyBitcodeModule(Buffer, Context); + ErrorOr MOrErr = getLazyBitcodeModule(std::move(Buffer), Context); if (std::error_code EC = MOrErr.getError()) message(LDPL_FATAL, "Could not read bitcode from file : %s", diff --git a/unittests/Bitcode/BitReaderTest.cpp b/unittests/Bitcode/BitReaderTest.cpp index eb6c125b79b..a27332b5b35 100644 --- a/unittests/Bitcode/BitReaderTest.cpp +++ b/unittests/Bitcode/BitReaderTest.cpp @@ -53,7 +53,8 @@ static std::unique_ptr getLazyModuleFromAssembly(LLVMContext &Context, writeModuleToBuffer(parseAssembly(Assembly), Mem); std::unique_ptr Buffer = MemoryBuffer::getMemBuffer(Mem.str(), "test", false); - ErrorOr ModuleOrErr = getLazyBitcodeModule(Buffer, Context); + ErrorOr ModuleOrErr = + getLazyBitcodeModule(std::move(Buffer), Context); return std::unique_ptr(ModuleOrErr.get()); }