llvm.org GIT mirror llvm / 9aa0b5e
Remove some calls to std::move. Instead of moving out the data in a ErrorOr<std::unique_ptr<Foo>>, get a reference to it. Thanks to David Blaikie for the suggestion. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@214516 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 5 years ago
19 changed file(s) with 72 addition(s) and 73 deletion(s). Raw diff Collapse all Expand all
306306 ChildIt->getAsBinary();
307307 if (ChildBinOrErr.getError())
308308 continue;
309 std::unique_ptr ChildBin = std::move(ChildBinOrErr.get());
309 std::unique_ptr &ChildBin = ChildBinOrErr.get();
310310 if (ChildBin->isObject()) {
311311 std::unique_ptr OF(
312312 static_cast(ChildBin.release()));
634634 MemoryBuffer::getFile(FName);
635635 if (!MemBufOrErr)
636636 return false;
637 std::unique_ptr MemBuf = std::move(MemBufOrErr.get());
638 StringRef Str(MemBuf->getBufferStart(), MemBuf->getBufferSize());
637 MemoryBuffer &MemBuf = *MemBufOrErr.get();
638 StringRef Str(MemBuf.getBufferStart(), MemBuf.getBufferSize());
639639
640640 // If we have a UTF-16 byte order mark, convert to UTF-8 for parsing.
641 ArrayRef BufRef(MemBuf->getBufferStart(), MemBuf->getBufferEnd());
641 ArrayRef BufRef(MemBuf.getBufferStart(), MemBuf.getBufferEnd());
642642 std::string UTF8Buf;
643643 if (hasUTF16ByteOrderMark(BufRef)) {
644644 if (!convertUTF16ToUTF8String(BufRef, UTF8Buf))
181181 *Error = EC.message();
182182 return 2;
183183 }
184 std::unique_ptr F1 = std::move(F1OrErr.get());
184 MemoryBuffer &F1 = *F1OrErr.get();
185185
186186 ErrorOr> F2OrErr = MemoryBuffer::getFile(NameB);
187187 if (std::error_code EC = F2OrErr.getError()) {
189189 *Error = EC.message();
190190 return 2;
191191 }
192 std::unique_ptr F2 = std::move(F2OrErr.get());
192 MemoryBuffer &F2 = *F2OrErr.get();
193193
194194 // Okay, now that we opened the files, scan them for the first difference.
195 const char *File1Start = F1->getBufferStart();
196 const char *File2Start = F2->getBufferStart();
197 const char *File1End = F1->getBufferEnd();
198 const char *File2End = F2->getBufferEnd();
195 const char *File1Start = F1.getBufferStart();
196 const char *File2Start = F2.getBufferStart();
197 const char *File1End = F1.getBufferEnd();
198 const char *File2End = F2.getBufferEnd();
199199 const char *F1P = File1Start;
200200 const char *F2P = File2Start;
201 uint64_t A_size = F1->getBufferSize();
202 uint64_t B_size = F2->getBufferSize();
201 uint64_t A_size = F1.getBufferSize();
202 uint64_t B_size = F2.getBufferSize();
203203
204204 // Are the buffers identical? Common case: Handle this efficiently.
205205 if (A_size == B_size &&
3838 sys::fs::remove(LockFileName);
3939 return None;
4040 }
41 std::unique_ptr MB = std::move(MBOrErr.get());
41 MemoryBuffer &MB = *MBOrErr.get();
4242
4343 StringRef Hostname;
4444 StringRef PIDStr;
45 std::tie(Hostname, PIDStr) = getToken(MB->getBuffer(), " ");
45 std::tie(Hostname, PIDStr) = getToken(MB.getBuffer(), " ");
4646 PIDStr = PIDStr.substr(PIDStr.find_first_not_of(" "));
4747 int PID;
4848 if (!PIDStr.getAsInteger(10, PID)) {
456456 M.getContext().diagnose(DiagnosticInfoSampleProfile(Filename.data(), Msg));
457457 return false;
458458 }
459 std::unique_ptr Buffer = std::move(BufferOrErr.get());
460 line_iterator LineIt(*Buffer, '#');
459 MemoryBuffer &Buffer = *BufferOrErr.get();
460 line_iterator LineIt(Buffer, '#');
461461
462462 // Read the profile of each function. Since each function may be
463463 // mentioned more than once, and we are collecting flat profiles,
702702 MemberBuffer, sys::fs::file_magic::unknown, &Context);
703703 if (!ObjOrErr)
704704 continue; // FIXME: check only for "not an object file" errors.
705 std::unique_ptr Obj = std::move(ObjOrErr.get());
705 object::SymbolicFile &Obj = *ObjOrErr.get();
706706
707707 if (!StartOffset) {
708708 printMemberHeader(Out, "", sys::TimeValue::now(), 0, 0, 0, 0);
710710 print32BE(Out, 0);
711711 }
712712
713 for (const object::BasicSymbolRef &S : Obj->symbols()) {
713 for (const object::BasicSymbolRef &S : Obj.symbols()) {
714714 uint32_t Symflags = S.getFlags();
715715 if (Symflags & object::SymbolRef::SF_FormatSpecific)
716716 continue;
724724 MemberOffsetRefs.push_back(std::make_pair(Out.tell(), MemberNum));
725725 print32BE(Out, 0);
726726 }
727 MemberBuffer.reset(Obj->releaseBuffer());
727 MemberBuffer.reset(Obj.releaseBuffer());
728728 }
729729 Out << NameOS.str();
730730
762762 MemberBuffers.resize(NewMembers.size());
763763
764764 for (unsigned I = 0, N = NewMembers.size(); I < N; ++I) {
765 std::unique_ptr MemberBuffer;
765 std::unique_ptr &MemberBuffer = MemberBuffers[I];
766766 NewArchiveIterator &Member = NewMembers[I];
767767
768768 if (Member.isNewMember()) {
780780 failIfError(MemberBufferOrErr.getError());
781781 MemberBuffer = std::move(MemberBufferOrErr.get());
782782 }
783 MemberBuffers[I].reset(MemberBuffer.release());
784783 }
785784
786785 if (Symtab) {
482482 MemoryBuffer::getFileOrSTDIN(InputFilename);
483483 if (std::error_code EC = MemBufOrErr.getError())
484484 return Error("Error reading '" + InputFilename + "': " + EC.message());
485 std::unique_ptr MemBuf = std::move(MemBufOrErr.get());
486
487 if (MemBuf->getBufferSize() & 3)
485 MemoryBuffer &MemBuf = *MemBufOrErr.get();
486
487 if (MemBuf.getBufferSize() & 3)
488488 return Error("Bitcode stream should be a multiple of 4 bytes in length");
489489
490 const unsigned char *BufPtr = (const unsigned char *)MemBuf->getBufferStart();
491 const unsigned char *EndBufPtr = BufPtr+MemBuf->getBufferSize();
490 const unsigned char *BufPtr = (const unsigned char *)MemBuf.getBufferStart();
491 const unsigned char *EndBufPtr = BufPtr+MemBuf.getBufferSize();
492492
493493 // If we have a wrapper header, parse it and ignore the non-bc file contents.
494494 // The magic number is 0x0B17C0DE stored in little endian.
7979 errs() << Filename << ": " << EC.message() << '\n';
8080 return;
8181 }
82 std::unique_ptr Obj = std::move(ObjOrErr.get());
82 ObjectFile &Obj = *ObjOrErr.get();
8383
84 std::unique_ptr DICtx(DIContext::getDWARFContext(*Obj));
84 std::unique_ptr DICtx(DIContext::getDWARFContext(Obj));
8585
8686 outs() << Filename
87 << ":\tfile format " << Obj->getFileFormatName() << "\n\n";
87 << ":\tfile format " << Obj.getFileFormatName() << "\n\n";
8888 // Dump the complete DWARF structure.
8989 DICtx->dump(outs(), DumpType);
9090 }
10121012 createBinary(std::move(*BufferOrErr), &Context);
10131013 if (error(BinaryOrErr.getError(), Filename))
10141014 return;
1015 std::unique_ptr Bin = std::move(BinaryOrErr.get());
1016
1017 if (Archive *A = dyn_cast(Bin.get())) {
1015 Binary &Bin = *BinaryOrErr.get();
1016
1017 if (Archive *A = dyn_cast(&Bin)) {
10181018 if (ArchiveMap) {
10191019 Archive::symbol_iterator I = A->symbol_begin();
10201020 Archive::symbol_iterator E = A->symbol_end();
10551055 }
10561056 return;
10571057 }
1058 if (MachOUniversalBinary *UB = dyn_cast(Bin.get())) {
1058 if (MachOUniversalBinary *UB = dyn_cast(&Bin)) {
10591059 // If we have a list of architecture flags specified dump only those.
10601060 if (!ArchAll && ArchFlags.size() != 0) {
10611061 // Look for a slice in the universal binary that matches each ArchFlag.
10751075 ArchiveName.clear();
10761076 ArchitectureName.clear();
10771077 if (ObjOrErr) {
1078 std::unique_ptr Obj = std::move(ObjOrErr.get());
1078 ObjectFile &Obj = *ObjOrErr.get();
10791079 if (ArchFlags.size() > 1) {
10801080 if (PrintFileName)
10811081 ArchitectureName = I->getArchTypeName();
10821082 else
1083 outs() << "\n" << Obj->getFileName() << " (for architecture "
1083 outs() << "\n" << Obj.getFileName() << " (for architecture "
10841084 << I->getArchTypeName() << ")"
10851085 << ":\n";
10861086 }
1087 dumpSymbolNamesFromObject(*Obj, false, ArchiveName,
1087 dumpSymbolNamesFromObject(Obj, false, ArchiveName,
10881088 ArchitectureName);
10891089 } else if (!I->getAsArchive(A)) {
10901090 for (Archive::child_iterator AI = A->child_begin(),
11371137 std::string ArchiveName;
11381138 ArchiveName.clear();
11391139 if (ObjOrErr) {
1140 std::unique_ptr Obj = std::move(ObjOrErr.get());
1141 dumpSymbolNamesFromObject(*Obj, false);
1140 ObjectFile &Obj = *ObjOrErr.get();
1141 dumpSymbolNamesFromObject(Obj, false);
11421142 } else if (!I->getAsArchive(A)) {
11431143 for (Archive::child_iterator AI = A->child_begin(),
11441144 AE = A->child_end();
11761176 ArchiveName.clear();
11771177 ArchitectureName.clear();
11781178 if (ObjOrErr) {
1179 std::unique_ptr Obj = std::move(ObjOrErr.get());
1179 ObjectFile &Obj = *ObjOrErr.get();
11801180 if (PrintFileName) {
1181 if (isa(Obj.get()) && moreThanOneArch)
1181 if (isa(Obj) && moreThanOneArch)
11821182 ArchitectureName = I->getArchTypeName();
11831183 } else {
11841184 if (moreThanOneArch)
11851185 outs() << "\n";
1186 outs() << Obj->getFileName();
1187 if (isa(Obj.get()) && moreThanOneArch)
1186 outs() << Obj.getFileName();
1187 if (isa(Obj) && moreThanOneArch)
11881188 outs() << " (for architecture " << I->getArchTypeName() << ")";
11891189 outs() << ":\n";
11901190 }
1191 dumpSymbolNamesFromObject(*Obj, false, ArchiveName, ArchitectureName);
1191 dumpSymbolNamesFromObject(Obj, false, ArchiveName, ArchitectureName);
11921192 } else if (!I->getAsArchive(A)) {
11931193 for (Archive::child_iterator AI = A->child_begin(), AE = A->child_end();
11941194 AI != AE; ++AI) {
12191219 }
12201220 return;
12211221 }
1222 if (SymbolicFile *O = dyn_cast(Bin.get())) {
1222 if (SymbolicFile *O = dyn_cast(&Bin)) {
12231223 if (!checkMachOAndArchFlags(O, Filename))
12241224 return;
12251225 dumpSymbolNamesFromObject(*O, true);
890890 errs() << ToolName << ": '" << file << "': " << EC.message() << ".\n";
891891 return;
892892 }
893 std::unique_ptr binary = std::move(BinaryOrErr.get());
894
895 if (Archive *a = dyn_cast(binary.get()))
893 Binary &Binary = *BinaryOrErr.get();
894
895 if (Archive *a = dyn_cast(&Binary))
896896 DumpArchive(a);
897 else if (ObjectFile *o = dyn_cast(binary.get()))
897 else if (ObjectFile *o = dyn_cast(&Binary))
898898 DumpObject(o);
899899 else
900900 errs() << ToolName << ": '" << file << "': " << "Unrecognized file type.\n";
291291 reportError(File, EC);
292292 return;
293293 }
294 std::unique_ptr Binary = std::move(BinaryOrErr.get());
295
296 if (Archive *Arc = dyn_cast(Binary.get()))
294 Binary &Binary = *BinaryOrErr.get();
295
296 if (Archive *Arc = dyn_cast(&Binary))
297297 dumpArchive(Arc);
298 else if (ObjectFile *Obj = dyn_cast(Binary.get()))
298 else if (ObjectFile *Obj = dyn_cast(&Binary))
299299 dumpObject(Obj);
300300 else
301301 reportError(File, readobj_error::unrecognized_file_format);
457457 errs() << ToolName << ": " << file << ": " << EC.message() << ".\n";
458458 return;
459459 }
460 std::unique_ptr binary = std::move(BinaryOrErr.get());
461
462 if (Archive *a = dyn_cast(binary.get())) {
460 Binary &Bin = *BinaryOrErr.get();
461
462 if (Archive *a = dyn_cast(&Bin)) {
463463 // This is an archive. Iterate over each member and display its sizes.
464464 for (object::Archive::child_iterator i = a->child_begin(),
465465 e = a->child_end();
487487 }
488488 }
489489 } else if (MachOUniversalBinary *UB =
490 dyn_cast(binary.get())) {
490 dyn_cast(&Bin)) {
491491 // If we have a list of architecture flags specified dump only those.
492492 if (!ArchAll && ArchFlags.size() != 0) {
493493 // Look for a slice in the universal binary that matches each ArchFlag.
691691 }
692692 }
693693 }
694 } else if (ObjectFile *o = dyn_cast(binary.get())) {
694 } else if (ObjectFile *o = dyn_cast(&Bin)) {
695695 if (!checkMachOAndArchFlags(o, file))
696696 return;
697697 if (OutputFormat == sysv)
301301 Binary *DbgBin = nullptr;
302302 ErrorOr> BinaryOrErr = createBinary(Path);
303303 if (!error(BinaryOrErr.getError())) {
304 std::unique_ptr ParsedBinary = std::move(BinaryOrErr.get());
304 std::unique_ptr &ParsedBinary = BinaryOrErr.get();
305305 // Check if it's a universal binary.
306306 Bin = ParsedBinary.get();
307307 ParsedBinariesAndObjects.push_back(std::move(ParsedBinary));
168168 reportError(File, EC);
169169 return;
170170 }
171 std::unique_ptr Binary = std::move(BinaryOrErr.get());
172
173 if (Archive *Arc = dyn_cast(Binary.get()))
171 Binary &Binary = *BinaryOrErr.get();
172
173 if (Archive *Arc = dyn_cast(&Binary))
174174 dumpArchive(Arc);
175 else if (ObjectFile *Obj = dyn_cast(Binary.get()))
175 else if (ObjectFile *Obj = dyn_cast(&Binary))
176176 dumpVTables(Obj);
177177 else
178178 reportError(File, vtabledump_error::unrecognized_file_format);
405405 ErrorOr> BinaryOrErr = createBinary(InputFile);
406406 if (std::error_code EC = BinaryOrErr.getError())
407407 return Error("unable to read input: '" + EC.message() + "'");
408 std::unique_ptr Binary = std::move((BinaryOrErr.get()));
409
410 const MachOObjectFile *InputObject = dyn_cast(Binary.get());
408 Binary &Binary = *BinaryOrErr.get();
409
410 const MachOObjectFile *InputObject = dyn_cast(&Binary);
411411 if (!InputObject)
412412 return Error("Not a MachO object");
413413
3535 if (std::error_code EC = BinaryOrErr.getError())
3636 return EC;
3737
38 std::unique_ptr Binary = std::move(BinaryOrErr.get());
38 Binary &Binary = *BinaryOrErr.get();
3939 // TODO: If this is an archive, then burst it and dump each entry
40 if (ObjectFile *Obj = dyn_cast(Binary.get()))
40 if (ObjectFile *Obj = dyn_cast(&Binary))
4141 return dumpObject(*Obj);
4242
4343 return obj2yaml_error::unrecognized_file_format;
152152 return nullptr;
153153 }
154154
155 std::unique_ptr Buffer = std::move(BufferOr.get());
156 ErrorOr ModuleOr = parseBitcodeFile(Buffer.get(), Context);
155 MemoryBuffer *Buffer = BufferOr.get().get();
156 ErrorOr ModuleOr = parseBitcodeFile(Buffer, Context);
157157 if (!ModuleOr) {
158158 DEBUG(dbgs() << "error: " << ModuleOr.getError().message() << "\n");
159159 return nullptr;
12571257 << "': " << EC.message() << '\n';
12581258 return 2;
12591259 }
1260 std::unique_ptr File = std::move(FileOrErr.get());
1260 std::unique_ptr &File = FileOrErr.get();
12611261
12621262 if (File->getBufferSize() == 0) {
12631263 errs() << "FileCheck error: '" << InputFilename << "' is empty.\n";
191191 MemoryBuffer::getFileOrSTDIN(Input);
192192 if (!BufOrErr)
193193 return 1;
194 std::unique_ptr Buf = std::move(BufOrErr.get());
194 MemoryBuffer &Buf = *BufOrErr.get();
195195
196196 llvm::SourceMgr sm;
197197 if (DumpTokens) {
198 yaml::dumpTokens(Buf->getBuffer(), outs());
198 yaml::dumpTokens(Buf.getBuffer(), outs());
199199 }
200200
201201 if (DumpCanonical) {
202 yaml::Stream stream(Buf->getBuffer(), sm);
202 yaml::Stream stream(Buf.getBuffer(), sm);
203203 dumpStream(stream);
204204 }
205205 }