From: Rafael Espindola Date: Fri, 1 Aug 2014 14:31:55 +0000 (+0000) Subject: Remove some calls to std::move. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3f6481d0d31674dd3e3e772ffa4dc6df1c9fdb3d;p=platform%2Fupstream%2Fllvm.git Remove some calls to std::move. Instead of moving out the data in a ErrorOr>, get a reference to it. Thanks to David Blaikie for the suggestion. llvm-svn: 214516 --- diff --git a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp index 5025aa6..a86f85c 100644 --- a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp +++ b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp @@ -307,7 +307,7 @@ uint64_t MCJIT::getSymbolAddress(const std::string &Name, ChildIt->getAsBinary(); if (ChildBinOrErr.getError()) continue; - std::unique_ptr ChildBin = std::move(ChildBinOrErr.get()); + std::unique_ptr &ChildBin = ChildBinOrErr.get(); if (ChildBin->isObject()) { std::unique_ptr OF( static_cast(ChildBin.release())); diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp index 586ecea..4c1df5c 100644 --- a/llvm/lib/Support/CommandLine.cpp +++ b/llvm/lib/Support/CommandLine.cpp @@ -635,11 +635,11 @@ static bool ExpandResponseFile(const char *FName, StringSaver &Saver, MemoryBuffer::getFile(FName); if (!MemBufOrErr) return false; - std::unique_ptr MemBuf = std::move(MemBufOrErr.get()); - StringRef Str(MemBuf->getBufferStart(), MemBuf->getBufferSize()); + MemoryBuffer &MemBuf = *MemBufOrErr.get(); + StringRef Str(MemBuf.getBufferStart(), MemBuf.getBufferSize()); // If we have a UTF-16 byte order mark, convert to UTF-8 for parsing. - ArrayRef BufRef(MemBuf->getBufferStart(), MemBuf->getBufferEnd()); + ArrayRef BufRef(MemBuf.getBufferStart(), MemBuf.getBufferEnd()); std::string UTF8Buf; if (hasUTF16ByteOrderMark(BufRef)) { if (!convertUTF16ToUTF8String(BufRef, UTF8Buf)) diff --git a/llvm/lib/Support/FileUtilities.cpp b/llvm/lib/Support/FileUtilities.cpp index 8a23491..5316f04 100644 --- a/llvm/lib/Support/FileUtilities.cpp +++ b/llvm/lib/Support/FileUtilities.cpp @@ -182,7 +182,7 @@ int llvm::DiffFilesWithTolerance(StringRef NameA, *Error = EC.message(); return 2; } - std::unique_ptr F1 = std::move(F1OrErr.get()); + MemoryBuffer &F1 = *F1OrErr.get(); ErrorOr> F2OrErr = MemoryBuffer::getFile(NameB); if (std::error_code EC = F2OrErr.getError()) { @@ -190,17 +190,17 @@ int llvm::DiffFilesWithTolerance(StringRef NameA, *Error = EC.message(); return 2; } - std::unique_ptr F2 = std::move(F2OrErr.get()); + MemoryBuffer &F2 = *F2OrErr.get(); // Okay, now that we opened the files, scan them for the first difference. - const char *File1Start = F1->getBufferStart(); - const char *File2Start = F2->getBufferStart(); - const char *File1End = F1->getBufferEnd(); - const char *File2End = F2->getBufferEnd(); + const char *File1Start = F1.getBufferStart(); + const char *File2Start = F2.getBufferStart(); + const char *File1End = F1.getBufferEnd(); + const char *File2End = F2.getBufferEnd(); const char *F1P = File1Start; const char *F2P = File2Start; - uint64_t A_size = F1->getBufferSize(); - uint64_t B_size = F2->getBufferSize(); + uint64_t A_size = F1.getBufferSize(); + uint64_t B_size = F2.getBufferSize(); // Are the buffers identical? Common case: Handle this efficiently. if (A_size == B_size && diff --git a/llvm/lib/Support/LockFileManager.cpp b/llvm/lib/Support/LockFileManager.cpp index 3f224e0..8fc5801 100644 --- a/llvm/lib/Support/LockFileManager.cpp +++ b/llvm/lib/Support/LockFileManager.cpp @@ -39,11 +39,11 @@ LockFileManager::readLockFile(StringRef LockFileName) { sys::fs::remove(LockFileName); return None; } - std::unique_ptr MB = std::move(MBOrErr.get()); + MemoryBuffer &MB = *MBOrErr.get(); StringRef Hostname; StringRef PIDStr; - std::tie(Hostname, PIDStr) = getToken(MB->getBuffer(), " "); + std::tie(Hostname, PIDStr) = getToken(MB.getBuffer(), " "); PIDStr = PIDStr.substr(PIDStr.find_first_not_of(" ")); int PID; if (!PIDStr.getAsInteger(10, PID)) { diff --git a/llvm/lib/Transforms/Scalar/SampleProfile.cpp b/llvm/lib/Transforms/Scalar/SampleProfile.cpp index 73c97ff..56c5737 100644 --- a/llvm/lib/Transforms/Scalar/SampleProfile.cpp +++ b/llvm/lib/Transforms/Scalar/SampleProfile.cpp @@ -457,8 +457,8 @@ bool SampleModuleProfile::loadText() { M.getContext().diagnose(DiagnosticInfoSampleProfile(Filename.data(), Msg)); return false; } - std::unique_ptr Buffer = std::move(BufferOrErr.get()); - line_iterator LineIt(*Buffer, '#'); + MemoryBuffer &Buffer = *BufferOrErr.get(); + line_iterator LineIt(Buffer, '#'); // Read the profile of each function. Since each function may be // mentioned more than once, and we are collecting flat profiles, diff --git a/llvm/tools/llvm-ar/llvm-ar.cpp b/llvm/tools/llvm-ar/llvm-ar.cpp index 3d5482d..3d87597 100644 --- a/llvm/tools/llvm-ar/llvm-ar.cpp +++ b/llvm/tools/llvm-ar/llvm-ar.cpp @@ -703,7 +703,7 @@ writeSymbolTable(raw_fd_ostream &Out, ArrayRef Members, MemberBuffer, sys::fs::file_magic::unknown, &Context); if (!ObjOrErr) continue; // FIXME: check only for "not an object file" errors. - std::unique_ptr Obj = std::move(ObjOrErr.get()); + object::SymbolicFile &Obj = *ObjOrErr.get(); if (!StartOffset) { printMemberHeader(Out, "", sys::TimeValue::now(), 0, 0, 0, 0); @@ -711,7 +711,7 @@ writeSymbolTable(raw_fd_ostream &Out, ArrayRef Members, print32BE(Out, 0); } - for (const object::BasicSymbolRef &S : Obj->symbols()) { + for (const object::BasicSymbolRef &S : Obj.symbols()) { uint32_t Symflags = S.getFlags(); if (Symflags & object::SymbolRef::SF_FormatSpecific) continue; @@ -725,7 +725,7 @@ writeSymbolTable(raw_fd_ostream &Out, ArrayRef Members, MemberOffsetRefs.push_back(std::make_pair(Out.tell(), MemberNum)); print32BE(Out, 0); } - MemberBuffer.reset(Obj->releaseBuffer()); + MemberBuffer.reset(Obj.releaseBuffer()); } Out << NameOS.str(); @@ -763,7 +763,7 @@ static void performWriteOperation(ArchiveOperation Operation, MemberBuffers.resize(NewMembers.size()); for (unsigned I = 0, N = NewMembers.size(); I < N; ++I) { - std::unique_ptr MemberBuffer; + std::unique_ptr &MemberBuffer = MemberBuffers[I]; NewArchiveIterator &Member = NewMembers[I]; if (Member.isNewMember()) { @@ -781,7 +781,6 @@ static void performWriteOperation(ArchiveOperation Operation, failIfError(MemberBufferOrErr.getError()); MemberBuffer = std::move(MemberBufferOrErr.get()); } - MemberBuffers[I].reset(MemberBuffer.release()); } if (Symtab) { diff --git a/llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp b/llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp index 63145c0..24ebbc1 100644 --- a/llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp +++ b/llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp @@ -483,13 +483,13 @@ static int AnalyzeBitcode() { MemoryBuffer::getFileOrSTDIN(InputFilename); if (std::error_code EC = MemBufOrErr.getError()) return Error("Error reading '" + InputFilename + "': " + EC.message()); - std::unique_ptr MemBuf = std::move(MemBufOrErr.get()); + MemoryBuffer &MemBuf = *MemBufOrErr.get(); - if (MemBuf->getBufferSize() & 3) + if (MemBuf.getBufferSize() & 3) return Error("Bitcode stream should be a multiple of 4 bytes in length"); - const unsigned char *BufPtr = (const unsigned char *)MemBuf->getBufferStart(); - const unsigned char *EndBufPtr = BufPtr+MemBuf->getBufferSize(); + const unsigned char *BufPtr = (const unsigned char *)MemBuf.getBufferStart(); + const unsigned char *EndBufPtr = BufPtr+MemBuf.getBufferSize(); // If we have a wrapper header, parse it and ignore the non-bc file contents. // The magic number is 0x0B17C0DE stored in little endian. diff --git a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp index 33bb766..4e65d44 100644 --- a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp +++ b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp @@ -80,12 +80,12 @@ static void DumpInput(const StringRef &Filename) { errs() << Filename << ": " << EC.message() << '\n'; return; } - std::unique_ptr Obj = std::move(ObjOrErr.get()); + ObjectFile &Obj = *ObjOrErr.get(); - std::unique_ptr DICtx(DIContext::getDWARFContext(*Obj)); + std::unique_ptr DICtx(DIContext::getDWARFContext(Obj)); outs() << Filename - << ":\tfile format " << Obj->getFileFormatName() << "\n\n"; + << ":\tfile format " << Obj.getFileFormatName() << "\n\n"; // Dump the complete DWARF structure. DICtx->dump(outs(), DumpType); } diff --git a/llvm/tools/llvm-nm/llvm-nm.cpp b/llvm/tools/llvm-nm/llvm-nm.cpp index a16135e..d701426 100644 --- a/llvm/tools/llvm-nm/llvm-nm.cpp +++ b/llvm/tools/llvm-nm/llvm-nm.cpp @@ -1013,9 +1013,9 @@ static void dumpSymbolNamesFromFile(std::string &Filename) { createBinary(std::move(*BufferOrErr), &Context); if (error(BinaryOrErr.getError(), Filename)) return; - std::unique_ptr Bin = std::move(BinaryOrErr.get()); + Binary &Bin = *BinaryOrErr.get(); - if (Archive *A = dyn_cast(Bin.get())) { + if (Archive *A = dyn_cast(&Bin)) { if (ArchiveMap) { Archive::symbol_iterator I = A->symbol_begin(); Archive::symbol_iterator E = A->symbol_end(); @@ -1056,7 +1056,7 @@ static void dumpSymbolNamesFromFile(std::string &Filename) { } return; } - if (MachOUniversalBinary *UB = dyn_cast(Bin.get())) { + if (MachOUniversalBinary *UB = dyn_cast(&Bin)) { // If we have a list of architecture flags specified dump only those. if (!ArchAll && ArchFlags.size() != 0) { // Look for a slice in the universal binary that matches each ArchFlag. @@ -1076,16 +1076,16 @@ static void dumpSymbolNamesFromFile(std::string &Filename) { ArchiveName.clear(); ArchitectureName.clear(); if (ObjOrErr) { - std::unique_ptr Obj = std::move(ObjOrErr.get()); + ObjectFile &Obj = *ObjOrErr.get(); if (ArchFlags.size() > 1) { if (PrintFileName) ArchitectureName = I->getArchTypeName(); else - outs() << "\n" << Obj->getFileName() << " (for architecture " + outs() << "\n" << Obj.getFileName() << " (for architecture " << I->getArchTypeName() << ")" << ":\n"; } - dumpSymbolNamesFromObject(*Obj, false, ArchiveName, + dumpSymbolNamesFromObject(Obj, false, ArchiveName, ArchitectureName); } else if (!I->getAsArchive(A)) { for (Archive::child_iterator AI = A->child_begin(), @@ -1138,8 +1138,8 @@ static void dumpSymbolNamesFromFile(std::string &Filename) { std::string ArchiveName; ArchiveName.clear(); if (ObjOrErr) { - std::unique_ptr Obj = std::move(ObjOrErr.get()); - dumpSymbolNamesFromObject(*Obj, false); + ObjectFile &Obj = *ObjOrErr.get(); + dumpSymbolNamesFromObject(Obj, false); } else if (!I->getAsArchive(A)) { for (Archive::child_iterator AI = A->child_begin(), AE = A->child_end(); @@ -1177,19 +1177,19 @@ static void dumpSymbolNamesFromFile(std::string &Filename) { ArchiveName.clear(); ArchitectureName.clear(); if (ObjOrErr) { - std::unique_ptr Obj = std::move(ObjOrErr.get()); + ObjectFile &Obj = *ObjOrErr.get(); if (PrintFileName) { - if (isa(Obj.get()) && moreThanOneArch) + if (isa(Obj) && moreThanOneArch) ArchitectureName = I->getArchTypeName(); } else { if (moreThanOneArch) outs() << "\n"; - outs() << Obj->getFileName(); - if (isa(Obj.get()) && moreThanOneArch) + outs() << Obj.getFileName(); + if (isa(Obj) && moreThanOneArch) outs() << " (for architecture " << I->getArchTypeName() << ")"; outs() << ":\n"; } - dumpSymbolNamesFromObject(*Obj, false, ArchiveName, ArchitectureName); + dumpSymbolNamesFromObject(Obj, false, ArchiveName, ArchitectureName); } else if (!I->getAsArchive(A)) { for (Archive::child_iterator AI = A->child_begin(), AE = A->child_end(); AI != AE; ++AI) { @@ -1220,7 +1220,7 @@ static void dumpSymbolNamesFromFile(std::string &Filename) { } return; } - if (SymbolicFile *O = dyn_cast(Bin.get())) { + if (SymbolicFile *O = dyn_cast(&Bin)) { if (!checkMachOAndArchFlags(O, Filename)) return; dumpSymbolNamesFromObject(*O, true); diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index 8041a88..9e9526a 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -891,11 +891,11 @@ static void DumpInput(StringRef file) { errs() << ToolName << ": '" << file << "': " << EC.message() << ".\n"; return; } - std::unique_ptr binary = std::move(BinaryOrErr.get()); + Binary &Binary = *BinaryOrErr.get(); - if (Archive *a = dyn_cast(binary.get())) + if (Archive *a = dyn_cast(&Binary)) DumpArchive(a); - else if (ObjectFile *o = dyn_cast(binary.get())) + else if (ObjectFile *o = dyn_cast(&Binary)) DumpObject(o); else errs() << ToolName << ": '" << file << "': " << "Unrecognized file type.\n"; diff --git a/llvm/tools/llvm-readobj/llvm-readobj.cpp b/llvm/tools/llvm-readobj/llvm-readobj.cpp index 837b71f..6e5b835 100644 --- a/llvm/tools/llvm-readobj/llvm-readobj.cpp +++ b/llvm/tools/llvm-readobj/llvm-readobj.cpp @@ -292,11 +292,11 @@ static void dumpInput(StringRef File) { reportError(File, EC); return; } - std::unique_ptr Binary = std::move(BinaryOrErr.get()); + Binary &Binary = *BinaryOrErr.get(); - if (Archive *Arc = dyn_cast(Binary.get())) + if (Archive *Arc = dyn_cast(&Binary)) dumpArchive(Arc); - else if (ObjectFile *Obj = dyn_cast(Binary.get())) + else if (ObjectFile *Obj = dyn_cast(&Binary)) dumpObject(Obj); else reportError(File, readobj_error::unrecognized_file_format); diff --git a/llvm/tools/llvm-size/llvm-size.cpp b/llvm/tools/llvm-size/llvm-size.cpp index 0664d53..24c9cd8 100644 --- a/llvm/tools/llvm-size/llvm-size.cpp +++ b/llvm/tools/llvm-size/llvm-size.cpp @@ -458,9 +458,9 @@ static void PrintFileSectionSizes(StringRef file) { errs() << ToolName << ": " << file << ": " << EC.message() << ".\n"; return; } - std::unique_ptr binary = std::move(BinaryOrErr.get()); + Binary &Bin = *BinaryOrErr.get(); - if (Archive *a = dyn_cast(binary.get())) { + if (Archive *a = dyn_cast(&Bin)) { // This is an archive. Iterate over each member and display its sizes. for (object::Archive::child_iterator i = a->child_begin(), e = a->child_end(); @@ -488,7 +488,7 @@ static void PrintFileSectionSizes(StringRef file) { } } } else if (MachOUniversalBinary *UB = - dyn_cast(binary.get())) { + dyn_cast(&Bin)) { // If we have a list of architecture flags specified dump only those. if (!ArchAll && ArchFlags.size() != 0) { // Look for a slice in the universal binary that matches each ArchFlag. @@ -692,7 +692,7 @@ static void PrintFileSectionSizes(StringRef file) { } } } - } else if (ObjectFile *o = dyn_cast(binary.get())) { + } else if (ObjectFile *o = dyn_cast(&Bin)) { if (!checkMachOAndArchFlags(o, file)) return; if (OutputFormat == sysv) diff --git a/llvm/tools/llvm-symbolizer/LLVMSymbolize.cpp b/llvm/tools/llvm-symbolizer/LLVMSymbolize.cpp index 7c4743b..14e193a 100644 --- a/llvm/tools/llvm-symbolizer/LLVMSymbolize.cpp +++ b/llvm/tools/llvm-symbolizer/LLVMSymbolize.cpp @@ -302,7 +302,7 @@ LLVMSymbolizer::getOrCreateBinary(const std::string &Path) { Binary *DbgBin = nullptr; ErrorOr> BinaryOrErr = createBinary(Path); if (!error(BinaryOrErr.getError())) { - std::unique_ptr ParsedBinary = std::move(BinaryOrErr.get()); + std::unique_ptr &ParsedBinary = BinaryOrErr.get(); // Check if it's a universal binary. Bin = ParsedBinary.get(); ParsedBinariesAndObjects.push_back(std::move(ParsedBinary)); diff --git a/llvm/tools/llvm-vtabledump/llvm-vtabledump.cpp b/llvm/tools/llvm-vtabledump/llvm-vtabledump.cpp index d1d8aa4..2f6ccb0 100644 --- a/llvm/tools/llvm-vtabledump/llvm-vtabledump.cpp +++ b/llvm/tools/llvm-vtabledump/llvm-vtabledump.cpp @@ -169,11 +169,11 @@ static void dumpInput(StringRef File) { reportError(File, EC); return; } - std::unique_ptr Binary = std::move(BinaryOrErr.get()); + Binary &Binary = *BinaryOrErr.get(); - if (Archive *Arc = dyn_cast(Binary.get())) + if (Archive *Arc = dyn_cast(&Binary)) dumpArchive(Arc); - else if (ObjectFile *Obj = dyn_cast(Binary.get())) + else if (ObjectFile *Obj = dyn_cast(&Binary)) dumpVTables(Obj); else reportError(File, vtabledump_error::unrecognized_file_format); diff --git a/llvm/tools/macho-dump/macho-dump.cpp b/llvm/tools/macho-dump/macho-dump.cpp index bbc7aae..787aebc 100644 --- a/llvm/tools/macho-dump/macho-dump.cpp +++ b/llvm/tools/macho-dump/macho-dump.cpp @@ -406,9 +406,9 @@ int main(int argc, char **argv) { ErrorOr> BinaryOrErr = createBinary(InputFile); if (std::error_code EC = BinaryOrErr.getError()) return Error("unable to read input: '" + EC.message() + "'"); - std::unique_ptr Binary = std::move((BinaryOrErr.get())); + Binary &Binary = *BinaryOrErr.get(); - const MachOObjectFile *InputObject = dyn_cast(Binary.get()); + const MachOObjectFile *InputObject = dyn_cast(&Binary); if (!InputObject) return Error("Not a MachO object"); diff --git a/llvm/tools/obj2yaml/obj2yaml.cpp b/llvm/tools/obj2yaml/obj2yaml.cpp index 8d1c140..dbf5a4a 100644 --- a/llvm/tools/obj2yaml/obj2yaml.cpp +++ b/llvm/tools/obj2yaml/obj2yaml.cpp @@ -36,9 +36,9 @@ static std::error_code dumpInput(StringRef File) { if (std::error_code EC = BinaryOrErr.getError()) return EC; - std::unique_ptr Binary = std::move(BinaryOrErr.get()); + Binary &Binary = *BinaryOrErr.get(); // TODO: If this is an archive, then burst it and dump each entry - if (ObjectFile *Obj = dyn_cast(Binary.get())) + if (ObjectFile *Obj = dyn_cast(&Binary)) return dumpObject(*Obj); return obj2yaml_error::unrecognized_file_format; diff --git a/llvm/tools/verify-uselistorder/verify-uselistorder.cpp b/llvm/tools/verify-uselistorder/verify-uselistorder.cpp index f5699e4..a9666ac 100644 --- a/llvm/tools/verify-uselistorder/verify-uselistorder.cpp +++ b/llvm/tools/verify-uselistorder/verify-uselistorder.cpp @@ -153,8 +153,8 @@ std::unique_ptr TempFile::readBitcode(LLVMContext &Context) const { return nullptr; } - std::unique_ptr Buffer = std::move(BufferOr.get()); - ErrorOr ModuleOr = parseBitcodeFile(Buffer.get(), Context); + MemoryBuffer *Buffer = BufferOr.get().get(); + ErrorOr ModuleOr = parseBitcodeFile(Buffer, Context); if (!ModuleOr) { DEBUG(dbgs() << "error: " << ModuleOr.getError().message() << "\n"); return nullptr; diff --git a/llvm/utils/FileCheck/FileCheck.cpp b/llvm/utils/FileCheck/FileCheck.cpp index 9cd1fe7..8c62ae7 100644 --- a/llvm/utils/FileCheck/FileCheck.cpp +++ b/llvm/utils/FileCheck/FileCheck.cpp @@ -1258,7 +1258,7 @@ int main(int argc, char **argv) { << "': " << EC.message() << '\n'; return 2; } - std::unique_ptr File = std::move(FileOrErr.get()); + std::unique_ptr &File = FileOrErr.get(); if (File->getBufferSize() == 0) { errs() << "FileCheck error: '" << InputFilename << "' is empty.\n"; diff --git a/llvm/utils/yaml-bench/YAMLBench.cpp b/llvm/utils/yaml-bench/YAMLBench.cpp index e88ce5d..8bd1ea1 100644 --- a/llvm/utils/yaml-bench/YAMLBench.cpp +++ b/llvm/utils/yaml-bench/YAMLBench.cpp @@ -192,15 +192,15 @@ int main(int argc, char **argv) { MemoryBuffer::getFileOrSTDIN(Input); if (!BufOrErr) return 1; - std::unique_ptr Buf = std::move(BufOrErr.get()); + MemoryBuffer &Buf = *BufOrErr.get(); llvm::SourceMgr sm; if (DumpTokens) { - yaml::dumpTokens(Buf->getBuffer(), outs()); + yaml::dumpTokens(Buf.getBuffer(), outs()); } if (DumpCanonical) { - yaml::Stream stream(Buf->getBuffer(), sm); + yaml::Stream stream(Buf.getBuffer(), sm); dumpStream(stream); } }