diff --git a/include/llvm/Object/Binary.h b/include/llvm/Object/Binary.h index 91984cb5271..1fd997c082c 100644 --- a/include/llvm/Object/Binary.h +++ b/include/llvm/Object/Binary.h @@ -126,10 +126,11 @@ public: /// @brief Create a Binary from Source, autodetecting the file type. /// /// @param Source The data to create the Binary from. -ErrorOr createBinary(std::unique_ptr Source, - LLVMContext *Context = nullptr); +ErrorOr> +createBinary(std::unique_ptr Source, + LLVMContext *Context = nullptr); -ErrorOr createBinary(StringRef Path); +ErrorOr> createBinary(StringRef Path); } } diff --git a/include/llvm/Object/ObjectFile.h b/include/llvm/Object/ObjectFile.h index a4370a3f30d..bf35b8ff5b4 100644 --- a/include/llvm/Object/ObjectFile.h +++ b/include/llvm/Object/ObjectFile.h @@ -27,6 +27,8 @@ namespace llvm { namespace object { class ObjectFile; +class COFFObjectFile; +class MachOObjectFile; class SymbolRef; class symbol_iterator; @@ -343,11 +345,13 @@ public: /// @param ObjectPath The path to the object file. ObjectPath.isObject must /// return true. /// @brief Create ObjectFile from path. - static ErrorOr createObjectFile(StringRef ObjectPath); - static ErrorOr + static ErrorOr> + createObjectFile(StringRef ObjectPath); + + static ErrorOr> createObjectFile(std::unique_ptr &Object, sys::fs::file_magic Type); - static ErrorOr + static ErrorOr> createObjectFile(std::unique_ptr &Object) { return createObjectFile(Object, sys::fs::file_magic::unknown); } @@ -358,11 +362,13 @@ public: } public: - static ErrorOr + static ErrorOr> createCOFFObjectFile(std::unique_ptr Object); - static ErrorOr + + static ErrorOr> createELFObjectFile(std::unique_ptr &Object); - static ErrorOr + + static ErrorOr> createMachOObjectFile(std::unique_ptr &Object); }; diff --git a/include/llvm/Object/SymbolicFile.h b/include/llvm/Object/SymbolicFile.h index 77eef4a546a..a4b266867b4 100644 --- a/include/llvm/Object/SymbolicFile.h +++ b/include/llvm/Object/SymbolicFile.h @@ -142,15 +142,16 @@ public: } // construction aux. - static ErrorOr + static ErrorOr> createSymbolicFile(std::unique_ptr &Object, sys::fs::file_magic Type, LLVMContext *Context); - static ErrorOr + static ErrorOr> createSymbolicFile(std::unique_ptr &Object) { return createSymbolicFile(Object, sys::fs::file_magic::unknown, nullptr); } - static ErrorOr createSymbolicFile(StringRef ObjectPath); + static ErrorOr> + createSymbolicFile(StringRef ObjectPath); static inline bool classof(const Binary *v) { return v->isSymbolic(); diff --git a/lib/DebugInfo/DWARFUnit.cpp b/lib/DebugInfo/DWARFUnit.cpp index 39d0a0ff5a4..4ec3bdd5823 100644 --- a/lib/DebugInfo/DWARFUnit.cpp +++ b/lib/DebugInfo/DWARFUnit.cpp @@ -260,12 +260,12 @@ bool DWARFUnit::parseDWO() { sys::path::append(AbsolutePath, CompilationDir); } sys::path::append(AbsolutePath, DWOFileName); - ErrorOr DWOFile = + ErrorOr> DWOFile = object::ObjectFile::createObjectFile(AbsolutePath); if (!DWOFile) return false; // Reset DWOHolder. - DWO.reset(new DWOHolder(DWOFile.get())); + DWO.reset(new DWOHolder(DWOFile.get().get())); DWARFUnit *DWOCU = DWO->getUnit(); // Verify that compile unit in .dwo file is valid. if (!DWOCU || DWOCU->getDWOId() != getDWOId()) { diff --git a/lib/ExecutionEngine/RuntimeDyld/ObjectImageCommon.h b/lib/ExecutionEngine/RuntimeDyld/ObjectImageCommon.h index c3a21823bbc..51e39e32e7a 100644 --- a/lib/ExecutionEngine/RuntimeDyld/ObjectImageCommon.h +++ b/lib/ExecutionEngine/RuntimeDyld/ObjectImageCommon.h @@ -49,7 +49,7 @@ public: // FIXME: error checking? createObjectFile returns an ErrorOr // and should probably be checked for failure. std::unique_ptr Buf(Buffer->getMemBuffer()); - ObjFile.reset(object::ObjectFile::createObjectFile(Buf).get()); + ObjFile = std::move(object::ObjectFile::createObjectFile(Buf).get()); } ObjectImageCommon(std::unique_ptr Input) : ObjectImage(nullptr), ObjFile(std::move(Input)) {} diff --git a/lib/Object/Binary.cpp b/lib/Object/Binary.cpp index 552d5db89c5..89e9d732ce9 100644 --- a/lib/Object/Binary.cpp +++ b/lib/Object/Binary.cpp @@ -38,8 +38,9 @@ StringRef Binary::getFileName() const { return Data->getBufferIdentifier(); } -ErrorOr object::createBinary(std::unique_ptr Buffer, - LLVMContext *Context) { +ErrorOr> +object::createBinary(std::unique_ptr Buffer, + LLVMContext *Context) { sys::fs::file_magic Type = sys::fs::identify_magic(Buffer->getBuffer()); switch (Type) { @@ -74,7 +75,7 @@ ErrorOr object::createBinary(std::unique_ptr Buffer, llvm_unreachable("Unexpected Binary File Type"); } -ErrorOr object::createBinary(StringRef Path) { +ErrorOr> object::createBinary(StringRef Path) { ErrorOr> FileOrErr = MemoryBuffer::getFileOrSTDIN(Path); if (std::error_code EC = FileOrErr.getError()) diff --git a/lib/Object/COFFObjectFile.cpp b/lib/Object/COFFObjectFile.cpp index 46ef87d1568..5ba3b781c3f 100644 --- a/lib/Object/COFFObjectFile.cpp +++ b/lib/Object/COFFObjectFile.cpp @@ -1112,12 +1112,12 @@ ExportDirectoryEntryRef::getSymbolName(StringRef &Result) const { return object_error::success; } -ErrorOr +ErrorOr> ObjectFile::createCOFFObjectFile(std::unique_ptr Object) { std::error_code EC; std::unique_ptr Ret( new COFFObjectFile(std::move(Object), EC)); if (EC) return EC; - return Ret.release(); + return std::move(Ret); } diff --git a/lib/Object/ELFObjectFile.cpp b/lib/Object/ELFObjectFile.cpp index 4f0f60b6242..199ea35d9e7 100644 --- a/lib/Object/ELFObjectFile.cpp +++ b/lib/Object/ELFObjectFile.cpp @@ -17,7 +17,7 @@ namespace llvm { using namespace object; -ErrorOr +ErrorOr> ObjectFile::createELFObjectFile(std::unique_ptr &Obj) { std::pair Ident = getElfArchType(Obj->getBuffer()); @@ -80,7 +80,7 @@ ObjectFile::createELFObjectFile(std::unique_ptr &Obj) { if (EC) return EC; - return R.release(); + return std::move(R); } } // end namespace llvm diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index fe5c29d873e..613364d52e5 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -1721,7 +1721,7 @@ void MachOObjectFile::ReadULEB128s(uint64_t Index, } } -ErrorOr +ErrorOr> ObjectFile::createMachOObjectFile(std::unique_ptr &Buffer) { StringRef Magic = Buffer->getBuffer().slice(0, 4); std::error_code EC; @@ -1739,6 +1739,6 @@ ObjectFile::createMachOObjectFile(std::unique_ptr &Buffer) { if (EC) return EC; - return Ret.release(); + return std::move(Ret); } diff --git a/lib/Object/Object.cpp b/lib/Object/Object.cpp index 567d87f7a0e..2b3861b4bdc 100644 --- a/lib/Object/Object.cpp +++ b/lib/Object/Object.cpp @@ -60,9 +60,10 @@ wrap(const relocation_iterator *SI) { // ObjectFile creation LLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf) { std::unique_ptr Buf(unwrap(MemBuf)); - ErrorOr ObjOrErr(ObjectFile::createObjectFile(Buf)); + ErrorOr> ObjOrErr( + ObjectFile::createObjectFile(Buf)); Buf.release(); - ObjectFile *Obj = ObjOrErr ? ObjOrErr.get() : nullptr; + ObjectFile *Obj = ObjOrErr ? ObjOrErr.get().release() : nullptr; return wrap(Obj); } diff --git a/lib/Object/ObjectFile.cpp b/lib/Object/ObjectFile.cpp index f5488c6d52d..0e77541dec5 100644 --- a/lib/Object/ObjectFile.cpp +++ b/lib/Object/ObjectFile.cpp @@ -11,6 +11,8 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Object/COFF.h" +#include "llvm/Object/MachO.h" #include "llvm/Object/ObjectFile.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" @@ -45,7 +47,7 @@ section_iterator ObjectFile::getRelocatedSection(DataRefImpl Sec) const { return section_iterator(SectionRef(Sec, this)); } -ErrorOr +ErrorOr> ObjectFile::createObjectFile(std::unique_ptr &Object, sys::fs::file_magic Type) { if (Type == sys::fs::file_magic::unknown) @@ -82,7 +84,8 @@ ObjectFile::createObjectFile(std::unique_ptr &Object, llvm_unreachable("Unexpected Object File Type"); } -ErrorOr ObjectFile::createObjectFile(StringRef ObjectPath) { +ErrorOr> +ObjectFile::createObjectFile(StringRef ObjectPath) { ErrorOr> FileOrErr = MemoryBuffer::getFile(ObjectPath); if (std::error_code EC = FileOrErr.getError()) diff --git a/lib/Object/SymbolicFile.cpp b/lib/Object/SymbolicFile.cpp index 30cf1a03f41..790d5a75ba7 100644 --- a/lib/Object/SymbolicFile.cpp +++ b/lib/Object/SymbolicFile.cpp @@ -25,7 +25,7 @@ SymbolicFile::SymbolicFile(unsigned int Type, SymbolicFile::~SymbolicFile() {} -ErrorOr +ErrorOr> SymbolicFile::createSymbolicFile(std::unique_ptr &Object, sys::fs::file_magic Type, LLVMContext *Context) { diff --git a/lib/ProfileData/CoverageMappingReader.cpp b/lib/ProfileData/CoverageMappingReader.cpp index 75ade55e2ed..c58df0fc093 100644 --- a/lib/ProfileData/CoverageMappingReader.cpp +++ b/lib/ProfileData/CoverageMappingReader.cpp @@ -282,7 +282,7 @@ ObjectFileCoverageMappingReader::ObjectFileCoverageMappingReader( if (!File) error(File.getError()); else - Object.reset(File.get()); + Object = std::move(File.get()); } ObjectFileCoverageMappingReader::ObjectFileCoverageMappingReader( @@ -292,7 +292,7 @@ ObjectFileCoverageMappingReader::ObjectFileCoverageMappingReader( if (!File) error(File.getError()); else - Object.reset(File.get()); + Object = std::move(File.get()); } namespace { diff --git a/tools/lli/lli.cpp b/tools/lli/lli.cpp index 48828c1d68a..43aedd1526a 100644 --- a/tools/lli/lli.cpp +++ b/tools/lli/lli.cpp @@ -528,13 +528,13 @@ int main(int argc, char **argv, char * const *envp) { } for (unsigned i = 0, e = ExtraObjects.size(); i != e; ++i) { - ErrorOr Obj = + ErrorOr> Obj = object::ObjectFile::createObjectFile(ExtraObjects[i]); if (!Obj) { Err.print(argv[0], errs()); return 1; } - EE->addObjectFile(std::unique_ptr(Obj.get())); + EE->addObjectFile(std::move(Obj.get())); } for (unsigned i = 0, e = ExtraArchives.size(); i != e; ++i) { diff --git a/tools/llvm-ar/llvm-ar.cpp b/tools/llvm-ar/llvm-ar.cpp index f638e55c5c7..3d5482df9de 100644 --- a/tools/llvm-ar/llvm-ar.cpp +++ b/tools/llvm-ar/llvm-ar.cpp @@ -698,12 +698,12 @@ writeSymbolTable(raw_fd_ostream &Out, ArrayRef Members, E = Members.end(); I != E; ++I, ++MemberNum) { std::unique_ptr &MemberBuffer = Buffers[MemberNum]; - ErrorOr ObjOrErr = + ErrorOr> ObjOrErr = object::SymbolicFile::createSymbolicFile( MemberBuffer, sys::fs::file_magic::unknown, &Context); if (!ObjOrErr) continue; // FIXME: check only for "not an object file" errors. - std::unique_ptr Obj(ObjOrErr.get()); + std::unique_ptr Obj = std::move(ObjOrErr.get()); if (!StartOffset) { printMemberHeader(Out, "", sys::TimeValue::now(), 0, 0, 0, 0); diff --git a/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/tools/llvm-dwarfdump/llvm-dwarfdump.cpp index f44b0e3ef5e..414205a3c2a 100644 --- a/tools/llvm-dwarfdump/llvm-dwarfdump.cpp +++ b/tools/llvm-dwarfdump/llvm-dwarfdump.cpp @@ -74,12 +74,13 @@ static void DumpInput(const StringRef &Filename) { return; } - ErrorOr ObjOrErr(ObjectFile::createObjectFile(Buff.get())); + ErrorOr> ObjOrErr = + ObjectFile::createObjectFile(Buff.get()); if (std::error_code EC = ObjOrErr.getError()) { errs() << Filename << ": " << EC.message() << '\n'; return; } - std::unique_ptr Obj(ObjOrErr.get()); + std::unique_ptr Obj = std::move(ObjOrErr.get()); std::unique_ptr DICtx(DIContext::getDWARFContext(Obj.get())); diff --git a/tools/llvm-nm/llvm-nm.cpp b/tools/llvm-nm/llvm-nm.cpp index 07a85c401a3..1d216fb88c0 100644 --- a/tools/llvm-nm/llvm-nm.cpp +++ b/tools/llvm-nm/llvm-nm.cpp @@ -1009,11 +1009,11 @@ static void dumpSymbolNamesFromFile(std::string &Filename) { return; LLVMContext &Context = getGlobalContext(); - ErrorOr BinaryOrErr = + ErrorOr> BinaryOrErr = createBinary(std::move(*BufferOrErr), &Context); if (error(BinaryOrErr.getError(), Filename)) return; - std::unique_ptr Bin(BinaryOrErr.get()); + std::unique_ptr Bin = std::move(BinaryOrErr.get()); if (Archive *A = dyn_cast(Bin.get())) { if (ArchiveMap) { diff --git a/tools/llvm-objdump/MachODump.cpp b/tools/llvm-objdump/MachODump.cpp index 4b46ac4fc0b..a999110cb3c 100644 --- a/tools/llvm-objdump/MachODump.cpp +++ b/tools/llvm-objdump/MachODump.cpp @@ -202,8 +202,8 @@ void llvm::DisassembleInputMachO(StringRef Filename) { return; } - std::unique_ptr MachOOF(static_cast( - ObjectFile::createMachOObjectFile(Buff.get()).get())); + std::unique_ptr MachOOF = + std::move(ObjectFile::createMachOObjectFile(Buff.get()).get()); DisassembleInputMachO2(Filename, MachOOF.get()); } @@ -294,7 +294,7 @@ static void DisassembleInputMachO2(StringRef Filename, errs() << "llvm-objdump: " << Filename << ": " << EC.message() << '\n'; return; } - DbgObj = ObjectFile::createMachOObjectFile(Buf.get()).get(); + DbgObj = ObjectFile::createMachOObjectFile(Buf.get()).get().release(); } // Setup the DIContext diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp index 3cd48e7f0d1..26707a3fd04 100644 --- a/tools/llvm-objdump/llvm-objdump.cpp +++ b/tools/llvm-objdump/llvm-objdump.cpp @@ -884,12 +884,12 @@ static void DumpInput(StringRef file) { } // Attempt to open the binary. - ErrorOr BinaryOrErr = createBinary(file); + ErrorOr> BinaryOrErr = createBinary(file); if (std::error_code EC = BinaryOrErr.getError()) { errs() << ToolName << ": '" << file << "': " << EC.message() << ".\n"; return; } - std::unique_ptr binary(BinaryOrErr.get()); + std::unique_ptr binary = std::move(BinaryOrErr.get()); if (Archive *a = dyn_cast(binary.get())) DumpArchive(a); diff --git a/tools/llvm-readobj/llvm-readobj.cpp b/tools/llvm-readobj/llvm-readobj.cpp index 8d2a997a231..837b71f05dc 100644 --- a/tools/llvm-readobj/llvm-readobj.cpp +++ b/tools/llvm-readobj/llvm-readobj.cpp @@ -287,12 +287,12 @@ static void dumpInput(StringRef File) { } // Attempt to open the binary. - ErrorOr BinaryOrErr = createBinary(File); + ErrorOr> BinaryOrErr = createBinary(File); if (std::error_code EC = BinaryOrErr.getError()) { reportError(File, EC); return; } - std::unique_ptr Binary(BinaryOrErr.get()); + std::unique_ptr Binary = std::move(BinaryOrErr.get()); if (Archive *Arc = dyn_cast(Binary.get())) dumpArchive(Arc); diff --git a/tools/llvm-size/llvm-size.cpp b/tools/llvm-size/llvm-size.cpp index 50b52200ff4..0664d535b8b 100644 --- a/tools/llvm-size/llvm-size.cpp +++ b/tools/llvm-size/llvm-size.cpp @@ -453,12 +453,12 @@ static void PrintFileSectionSizes(StringRef file) { } // Attempt to open the binary. - ErrorOr BinaryOrErr = createBinary(file); + ErrorOr> BinaryOrErr = createBinary(file); if (std::error_code EC = BinaryOrErr.getError()) { errs() << ToolName << ": " << file << ": " << EC.message() << ".\n"; return; } - std::unique_ptr binary(BinaryOrErr.get()); + std::unique_ptr binary = std::move(BinaryOrErr.get()); if (Archive *a = dyn_cast(binary.get())) { // This is an archive. Iterate over each member and display its sizes. diff --git a/tools/llvm-symbolizer/LLVMSymbolize.cpp b/tools/llvm-symbolizer/LLVMSymbolize.cpp index c1d39efc1b8..630f629b9a4 100644 --- a/tools/llvm-symbolizer/LLVMSymbolize.cpp +++ b/tools/llvm-symbolizer/LLVMSymbolize.cpp @@ -300,9 +300,9 @@ LLVMSymbolizer::getOrCreateBinary(const std::string &Path) { return I->second; Binary *Bin = nullptr; Binary *DbgBin = nullptr; - ErrorOr BinaryOrErr = createBinary(Path); + ErrorOr> BinaryOrErr = createBinary(Path); if (!error(BinaryOrErr.getError())) { - std::unique_ptr ParsedBinary(BinaryOrErr.get()); + std::unique_ptr ParsedBinary = std::move(BinaryOrErr.get()); // Check if it's a universal binary. Bin = ParsedBinary.get(); ParsedBinariesAndObjects.push_back(std::move(ParsedBinary)); @@ -314,8 +314,8 @@ LLVMSymbolizer::getOrCreateBinary(const std::string &Path) { BinaryOrErr = createBinary(ResourcePath); std::error_code EC = BinaryOrErr.getError(); if (EC != errc::no_such_file_or_directory && !error(EC)) { - DbgBin = BinaryOrErr.get(); - ParsedBinariesAndObjects.push_back(std::unique_ptr(DbgBin)); + DbgBin = BinaryOrErr.get().get(); + ParsedBinariesAndObjects.push_back(std::move(BinaryOrErr.get())); } } // Try to locate the debug binary using .gnu_debuglink section. @@ -327,8 +327,8 @@ LLVMSymbolizer::getOrCreateBinary(const std::string &Path) { findDebugBinary(Path, DebuglinkName, CRCHash, DebugBinaryPath)) { BinaryOrErr = createBinary(DebugBinaryPath); if (!error(BinaryOrErr.getError())) { - DbgBin = BinaryOrErr.get(); - ParsedBinariesAndObjects.push_back(std::unique_ptr(DbgBin)); + DbgBin = BinaryOrErr.get().get(); + ParsedBinariesAndObjects.push_back(std::move(BinaryOrErr.get())); } } } diff --git a/tools/llvm-vtabledump/llvm-vtabledump.cpp b/tools/llvm-vtabledump/llvm-vtabledump.cpp index da08b7d9d74..d1d8aa4082b 100644 --- a/tools/llvm-vtabledump/llvm-vtabledump.cpp +++ b/tools/llvm-vtabledump/llvm-vtabledump.cpp @@ -164,12 +164,12 @@ static void dumpInput(StringRef File) { } // Attempt to open the binary. - ErrorOr BinaryOrErr = createBinary(File); + ErrorOr> BinaryOrErr = createBinary(File); if (std::error_code EC = BinaryOrErr.getError()) { reportError(File, EC); return; } - std::unique_ptr Binary(BinaryOrErr.get()); + std::unique_ptr Binary = std::move(BinaryOrErr.get()); if (Archive *Arc = dyn_cast(Binary.get())) dumpArchive(Arc); diff --git a/tools/macho-dump/macho-dump.cpp b/tools/macho-dump/macho-dump.cpp index 760097974db..bbc7aae9f44 100644 --- a/tools/macho-dump/macho-dump.cpp +++ b/tools/macho-dump/macho-dump.cpp @@ -403,10 +403,10 @@ int main(int argc, char **argv) { cl::ParseCommandLineOptions(argc, argv, "llvm Mach-O dumping tool\n"); - ErrorOr BinaryOrErr = createBinary(InputFile); + ErrorOr> BinaryOrErr = createBinary(InputFile); if (std::error_code EC = BinaryOrErr.getError()) return Error("unable to read input: '" + EC.message() + "'"); - std::unique_ptr Binary(BinaryOrErr.get()); + std::unique_ptr Binary = std::move((BinaryOrErr.get())); const MachOObjectFile *InputObject = dyn_cast(Binary.get()); if (!InputObject) diff --git a/tools/obj2yaml/obj2yaml.cpp b/tools/obj2yaml/obj2yaml.cpp index 944314a923f..8d1c1409f18 100644 --- a/tools/obj2yaml/obj2yaml.cpp +++ b/tools/obj2yaml/obj2yaml.cpp @@ -32,11 +32,11 @@ static std::error_code dumpInput(StringRef File) { if (File != "-" && !sys::fs::exists(File)) return obj2yaml_error::file_not_found; - ErrorOr BinaryOrErr = createBinary(File); + ErrorOr> BinaryOrErr = createBinary(File); if (std::error_code EC = BinaryOrErr.getError()) return EC; - std::unique_ptr Binary(BinaryOrErr.get()); + std::unique_ptr Binary = std::move(BinaryOrErr.get()); // TODO: If this is an archive, then burst it and dump each entry if (ObjectFile *Obj = dyn_cast(Binary.get())) return dumpObject(*Obj);