1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

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.

llvm-svn: 214516
This commit is contained in:
Rafael Espindola 2014-08-01 14:31:55 +00:00
parent 18654adb14
commit 19e7ab14ac
19 changed files with 65 additions and 66 deletions

View File

@ -307,7 +307,7 @@ uint64_t MCJIT::getSymbolAddress(const std::string &Name,
ChildIt->getAsBinary();
if (ChildBinOrErr.getError())
continue;
std::unique_ptr<object::Binary> ChildBin = std::move(ChildBinOrErr.get());
std::unique_ptr<object::Binary> &ChildBin = ChildBinOrErr.get();
if (ChildBin->isObject()) {
std::unique_ptr<object::ObjectFile> OF(
static_cast<object::ObjectFile *>(ChildBin.release()));

View File

@ -635,11 +635,11 @@ static bool ExpandResponseFile(const char *FName, StringSaver &Saver,
MemoryBuffer::getFile(FName);
if (!MemBufOrErr)
return false;
std::unique_ptr<MemoryBuffer> 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<char> BufRef(MemBuf->getBufferStart(), MemBuf->getBufferEnd());
ArrayRef<char> BufRef(MemBuf.getBufferStart(), MemBuf.getBufferEnd());
std::string UTF8Buf;
if (hasUTF16ByteOrderMark(BufRef)) {
if (!convertUTF16ToUTF8String(BufRef, UTF8Buf))

View File

@ -182,7 +182,7 @@ int llvm::DiffFilesWithTolerance(StringRef NameA,
*Error = EC.message();
return 2;
}
std::unique_ptr<MemoryBuffer> F1 = std::move(F1OrErr.get());
MemoryBuffer &F1 = *F1OrErr.get();
ErrorOr<std::unique_ptr<MemoryBuffer>> 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<MemoryBuffer> 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 &&

View File

@ -39,11 +39,11 @@ LockFileManager::readLockFile(StringRef LockFileName) {
sys::fs::remove(LockFileName);
return None;
}
std::unique_ptr<MemoryBuffer> 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)) {

View File

@ -457,8 +457,8 @@ bool SampleModuleProfile::loadText() {
M.getContext().diagnose(DiagnosticInfoSampleProfile(Filename.data(), Msg));
return false;
}
std::unique_ptr<MemoryBuffer> 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,

View File

@ -703,7 +703,7 @@ writeSymbolTable(raw_fd_ostream &Out, ArrayRef<NewArchiveIterator> Members,
MemberBuffer, sys::fs::file_magic::unknown, &Context);
if (!ObjOrErr)
continue; // FIXME: check only for "not an object file" errors.
std::unique_ptr<object::SymbolicFile> 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<NewArchiveIterator> 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<NewArchiveIterator> 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<MemoryBuffer> MemberBuffer;
std::unique_ptr<MemoryBuffer> &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) {

View File

@ -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<MemoryBuffer> 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.

View File

@ -80,12 +80,12 @@ static void DumpInput(const StringRef &Filename) {
errs() << Filename << ": " << EC.message() << '\n';
return;
}
std::unique_ptr<ObjectFile> Obj = std::move(ObjOrErr.get());
ObjectFile &Obj = *ObjOrErr.get();
std::unique_ptr<DIContext> DICtx(DIContext::getDWARFContext(*Obj));
std::unique_ptr<DIContext> 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);
}

View File

@ -1013,9 +1013,9 @@ static void dumpSymbolNamesFromFile(std::string &Filename) {
createBinary(std::move(*BufferOrErr), &Context);
if (error(BinaryOrErr.getError(), Filename))
return;
std::unique_ptr<Binary> Bin = std::move(BinaryOrErr.get());
Binary &Bin = *BinaryOrErr.get();
if (Archive *A = dyn_cast<Archive>(Bin.get())) {
if (Archive *A = dyn_cast<Archive>(&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<MachOUniversalBinary>(Bin.get())) {
if (MachOUniversalBinary *UB = dyn_cast<MachOUniversalBinary>(&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<ObjectFile> 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<ObjectFile> 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<ObjectFile> Obj = std::move(ObjOrErr.get());
ObjectFile &Obj = *ObjOrErr.get();
if (PrintFileName) {
if (isa<MachOObjectFile>(Obj.get()) && moreThanOneArch)
if (isa<MachOObjectFile>(Obj) && moreThanOneArch)
ArchitectureName = I->getArchTypeName();
} else {
if (moreThanOneArch)
outs() << "\n";
outs() << Obj->getFileName();
if (isa<MachOObjectFile>(Obj.get()) && moreThanOneArch)
outs() << Obj.getFileName();
if (isa<MachOObjectFile>(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<SymbolicFile>(Bin.get())) {
if (SymbolicFile *O = dyn_cast<SymbolicFile>(&Bin)) {
if (!checkMachOAndArchFlags(O, Filename))
return;
dumpSymbolNamesFromObject(*O, true);

View File

@ -891,11 +891,11 @@ static void DumpInput(StringRef file) {
errs() << ToolName << ": '" << file << "': " << EC.message() << ".\n";
return;
}
std::unique_ptr<Binary> binary = std::move(BinaryOrErr.get());
Binary &Binary = *BinaryOrErr.get();
if (Archive *a = dyn_cast<Archive>(binary.get()))
if (Archive *a = dyn_cast<Archive>(&Binary))
DumpArchive(a);
else if (ObjectFile *o = dyn_cast<ObjectFile>(binary.get()))
else if (ObjectFile *o = dyn_cast<ObjectFile>(&Binary))
DumpObject(o);
else
errs() << ToolName << ": '" << file << "': " << "Unrecognized file type.\n";

View File

@ -292,11 +292,11 @@ static void dumpInput(StringRef File) {
reportError(File, EC);
return;
}
std::unique_ptr<Binary> Binary = std::move(BinaryOrErr.get());
Binary &Binary = *BinaryOrErr.get();
if (Archive *Arc = dyn_cast<Archive>(Binary.get()))
if (Archive *Arc = dyn_cast<Archive>(&Binary))
dumpArchive(Arc);
else if (ObjectFile *Obj = dyn_cast<ObjectFile>(Binary.get()))
else if (ObjectFile *Obj = dyn_cast<ObjectFile>(&Binary))
dumpObject(Obj);
else
reportError(File, readobj_error::unrecognized_file_format);

View File

@ -458,9 +458,9 @@ static void PrintFileSectionSizes(StringRef file) {
errs() << ToolName << ": " << file << ": " << EC.message() << ".\n";
return;
}
std::unique_ptr<Binary> binary = std::move(BinaryOrErr.get());
Binary &Bin = *BinaryOrErr.get();
if (Archive *a = dyn_cast<Archive>(binary.get())) {
if (Archive *a = dyn_cast<Archive>(&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<MachOUniversalBinary>(binary.get())) {
dyn_cast<MachOUniversalBinary>(&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<ObjectFile>(binary.get())) {
} else if (ObjectFile *o = dyn_cast<ObjectFile>(&Bin)) {
if (!checkMachOAndArchFlags(o, file))
return;
if (OutputFormat == sysv)

View File

@ -302,7 +302,7 @@ LLVMSymbolizer::getOrCreateBinary(const std::string &Path) {
Binary *DbgBin = nullptr;
ErrorOr<std::unique_ptr<Binary>> BinaryOrErr = createBinary(Path);
if (!error(BinaryOrErr.getError())) {
std::unique_ptr<Binary> ParsedBinary = std::move(BinaryOrErr.get());
std::unique_ptr<Binary> &ParsedBinary = BinaryOrErr.get();
// Check if it's a universal binary.
Bin = ParsedBinary.get();
ParsedBinariesAndObjects.push_back(std::move(ParsedBinary));

View File

@ -169,11 +169,11 @@ static void dumpInput(StringRef File) {
reportError(File, EC);
return;
}
std::unique_ptr<Binary> Binary = std::move(BinaryOrErr.get());
Binary &Binary = *BinaryOrErr.get();
if (Archive *Arc = dyn_cast<Archive>(Binary.get()))
if (Archive *Arc = dyn_cast<Archive>(&Binary))
dumpArchive(Arc);
else if (ObjectFile *Obj = dyn_cast<ObjectFile>(Binary.get()))
else if (ObjectFile *Obj = dyn_cast<ObjectFile>(&Binary))
dumpVTables(Obj);
else
reportError(File, vtabledump_error::unrecognized_file_format);

View File

@ -406,9 +406,9 @@ int main(int argc, char **argv) {
ErrorOr<std::unique_ptr<Binary>> BinaryOrErr = createBinary(InputFile);
if (std::error_code EC = BinaryOrErr.getError())
return Error("unable to read input: '" + EC.message() + "'");
std::unique_ptr<Binary> Binary = std::move((BinaryOrErr.get()));
Binary &Binary = *BinaryOrErr.get();
const MachOObjectFile *InputObject = dyn_cast<MachOObjectFile>(Binary.get());
const MachOObjectFile *InputObject = dyn_cast<MachOObjectFile>(&Binary);
if (!InputObject)
return Error("Not a MachO object");

View File

@ -36,9 +36,9 @@ static std::error_code dumpInput(StringRef File) {
if (std::error_code EC = BinaryOrErr.getError())
return EC;
std::unique_ptr<Binary> 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<ObjectFile>(Binary.get()))
if (ObjectFile *Obj = dyn_cast<ObjectFile>(&Binary))
return dumpObject(*Obj);
return obj2yaml_error::unrecognized_file_format;

View File

@ -153,8 +153,8 @@ std::unique_ptr<Module> TempFile::readBitcode(LLVMContext &Context) const {
return nullptr;
}
std::unique_ptr<MemoryBuffer> Buffer = std::move(BufferOr.get());
ErrorOr<Module *> ModuleOr = parseBitcodeFile(Buffer.get(), Context);
MemoryBuffer *Buffer = BufferOr.get().get();
ErrorOr<Module *> ModuleOr = parseBitcodeFile(Buffer, Context);
if (!ModuleOr) {
DEBUG(dbgs() << "error: " << ModuleOr.getError().message() << "\n");
return nullptr;

View File

@ -1258,7 +1258,7 @@ int main(int argc, char **argv) {
<< "': " << EC.message() << '\n';
return 2;
}
std::unique_ptr<MemoryBuffer> File = std::move(FileOrErr.get());
std::unique_ptr<MemoryBuffer> &File = FileOrErr.get();
if (File->getBufferSize() == 0) {
errs() << "FileCheck error: '" << InputFilename << "' is empty.\n";

View File

@ -192,15 +192,15 @@ int main(int argc, char **argv) {
MemoryBuffer::getFileOrSTDIN(Input);
if (!BufOrErr)
return 1;
std::unique_ptr<MemoryBuffer> 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);
}
}