From 0d50598d71c5cc81c0e777a0ddf3e692e634f565 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 24 Jun 2014 13:56:32 +0000 Subject: Pass a unique_ptr to the constructors in the Binary hierarchy. Once the objects are constructed, they own the buffer. Passing a unique_ptr makes that clear. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211595 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Object/Archive.h | 4 +-- include/llvm/Object/Binary.h | 2 +- include/llvm/Object/COFF.h | 2 +- include/llvm/Object/ELFObjectFile.h | 9 +++--- include/llvm/Object/IRObjectFile.h | 3 +- include/llvm/Object/MachO.h | 4 +-- include/llvm/Object/MachOUniversal.h | 6 ++-- include/llvm/Object/ObjectFile.h | 5 +-- include/llvm/Object/SymbolicFile.h | 7 +++-- lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp | 36 ++++++++++++---------- lib/Object/Archive.cpp | 13 ++++---- lib/Object/Binary.cpp | 8 ++--- lib/Object/COFFObjectFile.cpp | 11 ++++--- lib/Object/ELFObjectFile.cpp | 16 +++++----- lib/Object/IRObjectFile.cpp | 17 +++++----- lib/Object/MachOObjectFile.cpp | 15 ++++----- lib/Object/MachOUniversal.cpp | 17 +++++----- lib/Object/ObjectFile.cpp | 6 ++-- lib/Object/SymbolicFile.cpp | 7 +++-- tools/lli/lli.cpp | 2 +- tools/llvm-ar/llvm-ar.cpp | 2 +- 21 files changed, 104 insertions(+), 88 deletions(-) diff --git a/include/llvm/Object/Archive.h b/include/llvm/Object/Archive.h index 4fe44a7769..af6c995c1d 100644 --- a/include/llvm/Object/Archive.h +++ b/include/llvm/Object/Archive.h @@ -164,8 +164,8 @@ public: } }; - Archive(MemoryBuffer *source, std::error_code &ec); - static ErrorOr create(MemoryBuffer *Source); + Archive(std::unique_ptr Source, std::error_code &EC); + static ErrorOr create(std::unique_ptr Source); enum Kind { K_GNU, diff --git a/include/llvm/Object/Binary.h b/include/llvm/Object/Binary.h index 258a885d4f..9be2fbe083 100644 --- a/include/llvm/Object/Binary.h +++ b/include/llvm/Object/Binary.h @@ -36,7 +36,7 @@ private: protected: std::unique_ptr Data; - Binary(unsigned int Type, MemoryBuffer *Source); + Binary(unsigned int Type, std::unique_ptr Source); enum { ID_Archive, diff --git a/include/llvm/Object/COFF.h b/include/llvm/Object/COFF.h index 1f45ab05db..e2da070d47 100644 --- a/include/llvm/Object/COFF.h +++ b/include/llvm/Object/COFF.h @@ -420,7 +420,7 @@ protected: StringRef &Result) const override; public: - COFFObjectFile(MemoryBuffer *Object, std::error_code &EC); + COFFObjectFile(std::unique_ptr Object, std::error_code &EC); basic_symbol_iterator symbol_begin_impl() const override; basic_symbol_iterator symbol_end_impl() const override; library_iterator needed_library_begin() const override; diff --git a/include/llvm/Object/ELFObjectFile.h b/include/llvm/Object/ELFObjectFile.h index 72f7216110..ae74ebc02c 100644 --- a/include/llvm/Object/ELFObjectFile.h +++ b/include/llvm/Object/ELFObjectFile.h @@ -177,7 +177,7 @@ protected: bool isDyldELFObject; public: - ELFObjectFile(MemoryBuffer *Object, std::error_code &EC); + ELFObjectFile(std::unique_ptr Object, std::error_code &EC); const Elf_Sym *getSymbol(DataRefImpl Symb) const; @@ -773,12 +773,13 @@ ELFObjectFile::getRela(DataRefImpl Rela) const { } template -ELFObjectFile::ELFObjectFile(MemoryBuffer *Object, std::error_code &ec) +ELFObjectFile::ELFObjectFile(std::unique_ptr Object, + std::error_code &EC) : ObjectFile(getELFType(static_cast(ELFT::TargetEndianness) == support::little, ELFT::Is64Bits), - Object), - EF(Object, ec) {} + std::move(Object)), + EF(Data.get(), EC) {} template basic_symbol_iterator ELFObjectFile::symbol_begin_impl() const { diff --git a/include/llvm/Object/IRObjectFile.h b/include/llvm/Object/IRObjectFile.h index 97a75b763d..3e6817554e 100644 --- a/include/llvm/Object/IRObjectFile.h +++ b/include/llvm/Object/IRObjectFile.h @@ -27,7 +27,8 @@ class IRObjectFile : public SymbolicFile { std::unique_ptr Mang; public: - IRObjectFile(MemoryBuffer *Object, std::error_code &EC, LLVMContext &Context); + IRObjectFile(std::unique_ptr Object, std::error_code &EC, + LLVMContext &Context); ~IRObjectFile(); void moveSymbolNext(DataRefImpl &Symb) const override; std::error_code printSymbolName(raw_ostream &OS, diff --git a/include/llvm/Object/MachO.h b/include/llvm/Object/MachO.h index 182815f49a..8b7f904c57 100644 --- a/include/llvm/Object/MachO.h +++ b/include/llvm/Object/MachO.h @@ -56,8 +56,8 @@ public: MachO::load_command C; // The command itself. }; - MachOObjectFile(MemoryBuffer *Object, bool IsLittleEndian, bool Is64Bits, - std::error_code &EC); + MachOObjectFile(std::unique_ptr Object, bool IsLittleEndian, + bool Is64Bits, std::error_code &EC); void moveSymbolNext(DataRefImpl &Symb) const override; std::error_code getSymbolName(DataRefImpl Symb, diff --git a/include/llvm/Object/MachOUniversal.h b/include/llvm/Object/MachOUniversal.h index 94fe99deec..268e1c839e 100644 --- a/include/llvm/Object/MachOUniversal.h +++ b/include/llvm/Object/MachOUniversal.h @@ -83,8 +83,10 @@ public: } }; - MachOUniversalBinary(MemoryBuffer *Source, std::error_code &ec); - static ErrorOr create(MemoryBuffer *Source); + MachOUniversalBinary(std::unique_ptr Source, + std::error_code &ec); + static ErrorOr + create(std::unique_ptr Source); object_iterator begin_objects() const { return ObjectForArch(this, 0); diff --git a/include/llvm/Object/ObjectFile.h b/include/llvm/Object/ObjectFile.h index 56799eb681..646abf80f8 100644 --- a/include/llvm/Object/ObjectFile.h +++ b/include/llvm/Object/ObjectFile.h @@ -208,7 +208,7 @@ class ObjectFile : public SymbolicFile { ObjectFile(const ObjectFile &other) LLVM_DELETED_FUNCTION; protected: - ObjectFile(unsigned int Type, MemoryBuffer *Source); + ObjectFile(unsigned int Type, std::unique_ptr Source); const uint8_t *base() const { return reinterpret_cast(Data->getBufferStart()); @@ -347,7 +347,8 @@ public: } public: - static ErrorOr createCOFFObjectFile(MemoryBuffer *Object); + static ErrorOr + createCOFFObjectFile(std::unique_ptr Object); static ErrorOr createELFObjectFile(std::unique_ptr &Object); static ErrorOr diff --git a/include/llvm/Object/SymbolicFile.h b/include/llvm/Object/SymbolicFile.h index 24908cde19..e48bf372a6 100644 --- a/include/llvm/Object/SymbolicFile.h +++ b/include/llvm/Object/SymbolicFile.h @@ -115,7 +115,7 @@ const uint64_t UnknownAddressOrSize = ~0ULL; class SymbolicFile : public Binary { public: virtual ~SymbolicFile(); - SymbolicFile(unsigned int Type, MemoryBuffer *Source); + SymbolicFile(unsigned int Type, std::unique_ptr Source); // virtual interface. virtual void moveSymbolNext(DataRefImpl &Symb) const = 0; @@ -142,8 +142,9 @@ public: } // construction aux. - static ErrorOr createIRObjectFile(MemoryBuffer *Object, - LLVMContext &Context); + static ErrorOr + createIRObjectFile(std::unique_ptr Object, + LLVMContext &Context); static ErrorOr createSymbolicFile(std::unique_ptr &Object, diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp index 03e0a36ab9..4dcbb1d1cb 100644 --- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp +++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp @@ -55,9 +55,9 @@ template class DyldELFObject : public ELFObjectFile { public: DyldELFObject(std::unique_ptr UnderlyingFile, - MemoryBuffer *Wrapper, std::error_code &ec); + std::unique_ptr Wrapper, std::error_code &ec); - DyldELFObject(MemoryBuffer *Wrapper, std::error_code &ec); + DyldELFObject(std::unique_ptr Wrapper, std::error_code &ec); void updateSectionAddress(const SectionRef &Sec, uint64_t Addr); void updateSymbolAddress(const SymbolRef &Sym, uint64_t Addr); @@ -109,15 +109,17 @@ public: // actual memory. Ultimately, the Binary parent class will take ownership of // this MemoryBuffer object but not the underlying memory. template -DyldELFObject::DyldELFObject(MemoryBuffer *Wrapper, std::error_code &ec) - : ELFObjectFile(Wrapper, ec) { +DyldELFObject::DyldELFObject(std::unique_ptr Wrapper, + std::error_code &EC) + : ELFObjectFile(std::move(Wrapper), EC) { this->isDyldELFObject = true; } template DyldELFObject::DyldELFObject(std::unique_ptr UnderlyingFile, - MemoryBuffer *Wrapper, std::error_code &ec) - : ELFObjectFile(Wrapper, ec), + std::unique_ptr Wrapper, + std::error_code &EC) + : ELFObjectFile(std::move(Wrapper), EC), UnderlyingFile(std::move(UnderlyingFile)) { this->isDyldELFObject = true; } @@ -183,29 +185,29 @@ RuntimeDyldELF::createObjectImageFromFile(std::unique_ptr Ob return nullptr; std::error_code ec; - MemoryBuffer *Buffer = - MemoryBuffer::getMemBuffer(ObjFile->getData(), "", false); + std::unique_ptr Buffer( + MemoryBuffer::getMemBuffer(ObjFile->getData(), "", false)); if (ObjFile->getBytesInAddress() == 4 && ObjFile->isLittleEndian()) { auto Obj = llvm::make_unique>>( - std::move(ObjFile), Buffer, ec); + std::move(ObjFile), std::move(Buffer), ec); return new ELFObjectImage>( nullptr, std::move(Obj)); } else if (ObjFile->getBytesInAddress() == 4 && !ObjFile->isLittleEndian()) { auto Obj = llvm::make_unique>>( - std::move(ObjFile), Buffer, ec); + std::move(ObjFile), std::move(Buffer), ec); return new ELFObjectImage>(nullptr, std::move(Obj)); } else if (ObjFile->getBytesInAddress() == 8 && !ObjFile->isLittleEndian()) { auto Obj = llvm::make_unique>>( - std::move(ObjFile), Buffer, ec); + std::move(ObjFile), std::move(Buffer), ec); return new ELFObjectImage>(nullptr, std::move(Obj)); } else if (ObjFile->getBytesInAddress() == 8 && ObjFile->isLittleEndian()) { auto Obj = llvm::make_unique>>( - std::move(ObjFile), Buffer, ec); + std::move(ObjFile), std::move(Buffer), ec); return new ELFObjectImage>( nullptr, std::move(Obj)); } else @@ -220,29 +222,31 @@ ObjectImage *RuntimeDyldELF::createObjectImage(ObjectBuffer *Buffer) { (uint8_t)Buffer->getBufferStart()[ELF::EI_DATA]); std::error_code ec; + std::unique_ptr Buf(Buffer->getMemBuffer()); + if (Ident.first == ELF::ELFCLASS32 && Ident.second == ELF::ELFDATA2LSB) { auto Obj = llvm::make_unique>>( - Buffer->getMemBuffer(), ec); + std::move(Buf), ec); return new ELFObjectImage>( Buffer, std::move(Obj)); } else if (Ident.first == ELF::ELFCLASS32 && Ident.second == ELF::ELFDATA2MSB) { auto Obj = llvm::make_unique>>( - Buffer->getMemBuffer(), ec); + std::move(Buf), ec); return new ELFObjectImage>(Buffer, std::move(Obj)); } else if (Ident.first == ELF::ELFCLASS64 && Ident.second == ELF::ELFDATA2MSB) { auto Obj = llvm::make_unique>>( - Buffer->getMemBuffer(), ec); + std::move(Buf), ec); return new ELFObjectImage>(Buffer, std::move(Obj)); } else if (Ident.first == ELF::ELFCLASS64 && Ident.second == ELF::ELFDATA2LSB) { auto Obj = llvm::make_unique>>( - Buffer->getMemBuffer(), ec); + std::move(Buf), ec); return new ELFObjectImage>(Buffer, std::move(Obj)); } else llvm_unreachable("Unexpected ELF format"); diff --git a/lib/Object/Archive.cpp b/lib/Object/Archive.cpp index cdf987a320..2393ade562 100644 --- a/lib/Object/Archive.cpp +++ b/lib/Object/Archive.cpp @@ -186,20 +186,19 @@ Archive::Child::getAsBinary(LLVMContext *Context) const { return createBinary(Buff, Context); } -ErrorOr Archive::create(MemoryBuffer *Source) { +ErrorOr Archive::create(std::unique_ptr Source) { std::error_code EC; - std::unique_ptr Ret(new Archive(Source, EC)); + std::unique_ptr Ret(new Archive(std::move(Source), EC)); if (EC) return EC; return Ret.release(); } -Archive::Archive(MemoryBuffer *source, std::error_code &ec) - : Binary(Binary::ID_Archive, source), SymbolTable(child_end()) { +Archive::Archive(std::unique_ptr Source, std::error_code &ec) + : Binary(Binary::ID_Archive, std::move(Source)), SymbolTable(child_end()) { // Check for sufficient magic. - assert(source); - if (source->getBufferSize() < 8 || - StringRef(source->getBufferStart(), 8) != Magic) { + if (Data->getBufferSize() < 8 || + StringRef(Data->getBufferStart(), 8) != Magic) { ec = object_error::invalid_file_type; return; } diff --git a/lib/Object/Binary.cpp b/lib/Object/Binary.cpp index ee6f58cd75..8d79a96662 100644 --- a/lib/Object/Binary.cpp +++ b/lib/Object/Binary.cpp @@ -27,8 +27,8 @@ using namespace object; Binary::~Binary() {} -Binary::Binary(unsigned int Type, MemoryBuffer *Source) - : TypeID(Type), Data(Source) {} +Binary::Binary(unsigned int Type, std::unique_ptr Source) + : TypeID(Type), Data(std::move(Source)) {} StringRef Binary::getData() const { return Data->getBuffer(); @@ -44,7 +44,7 @@ ErrorOr object::createBinary(std::unique_ptr &Buffer, switch (Type) { case sys::fs::file_magic::archive: - return Archive::create(Buffer.release()); + return Archive::create(std::move(Buffer)); case sys::fs::file_magic::elf_relocatable: case sys::fs::file_magic::elf_executable: case sys::fs::file_magic::elf_shared_object: @@ -65,7 +65,7 @@ ErrorOr object::createBinary(std::unique_ptr &Buffer, case sys::fs::file_magic::bitcode: return ObjectFile::createSymbolicFile(Buffer, Type, Context); case sys::fs::file_magic::macho_universal_binary: - return MachOUniversalBinary::create(Buffer.release()); + return MachOUniversalBinary::create(std::move(Buffer)); case sys::fs::file_magic::unknown: case sys::fs::file_magic::windows_resource: // Unrecognized object file format. diff --git a/lib/Object/COFFObjectFile.cpp b/lib/Object/COFFObjectFile.cpp index 1b149742eb..46ef87d156 100644 --- a/lib/Object/COFFObjectFile.cpp +++ b/lib/Object/COFFObjectFile.cpp @@ -511,8 +511,9 @@ std::error_code COFFObjectFile::initExportTablePtr() { return object_error::success; } -COFFObjectFile::COFFObjectFile(MemoryBuffer *Object, std::error_code &EC) - : ObjectFile(Binary::ID_COFF, Object), COFFHeader(nullptr), +COFFObjectFile::COFFObjectFile(std::unique_ptr Object, + std::error_code &EC) + : ObjectFile(Binary::ID_COFF, std::move(Object)), COFFHeader(nullptr), PE32Header(nullptr), PE32PlusHeader(nullptr), DataDirectory(nullptr), SectionTable(nullptr), SymbolTable(nullptr), StringTable(nullptr), StringTableSize(0), ImportDirectory(nullptr), NumberOfImportDirectory(0), @@ -1111,9 +1112,11 @@ ExportDirectoryEntryRef::getSymbolName(StringRef &Result) const { return object_error::success; } -ErrorOr ObjectFile::createCOFFObjectFile(MemoryBuffer *Object) { +ErrorOr +ObjectFile::createCOFFObjectFile(std::unique_ptr Object) { std::error_code EC; - std::unique_ptr Ret(new COFFObjectFile(Object, EC)); + std::unique_ptr Ret( + new COFFObjectFile(std::move(Object), EC)); if (EC) return EC; return Ret.release(); diff --git a/lib/Object/ELFObjectFile.cpp b/lib/Object/ELFObjectFile.cpp index a9165af79d..7095caf1a6 100644 --- a/lib/Object/ELFObjectFile.cpp +++ b/lib/Object/ELFObjectFile.cpp @@ -34,7 +34,7 @@ ObjectFile::createELFObjectFile(std::unique_ptr &Obj) { #endif if (MaxAlignment >= 2) R.reset(new ELFObjectFile>( - Obj.release(), EC)); + std::move(Obj), EC)); else return object_error::parse_failed; else if (Ident.first == ELF::ELFCLASS32 && Ident.second == ELF::ELFDATA2MSB) @@ -45,32 +45,32 @@ ObjectFile::createELFObjectFile(std::unique_ptr &Obj) { else #endif if (MaxAlignment >= 2) - R.reset(new ELFObjectFile>(Obj.release(), + R.reset(new ELFObjectFile>(std::move(Obj), EC)); else return object_error::parse_failed; else if (Ident.first == ELF::ELFCLASS64 && Ident.second == ELF::ELFDATA2MSB) #if !LLVM_IS_UNALIGNED_ACCESS_FAST if (MaxAlignment >= 8) - R.reset( - new ELFObjectFile>(Obj.release(), EC)); + R.reset(new ELFObjectFile>(std::move(Obj), + EC)); else #endif if (MaxAlignment >= 2) - R.reset( - new ELFObjectFile>(Obj.release(), EC)); + R.reset(new ELFObjectFile>(std::move(Obj), + EC)); else return object_error::parse_failed; else if (Ident.first == ELF::ELFCLASS64 && Ident.second == ELF::ELFDATA2LSB) { #if !LLVM_IS_UNALIGNED_ACCESS_FAST if (MaxAlignment >= 8) R.reset(new ELFObjectFile>( - Obj.release(), EC)); + std::move(Obj), EC)); else #endif if (MaxAlignment >= 2) R.reset(new ELFObjectFile>( - Obj.release(), EC)); + std::move(Obj), EC)); else return object_error::parse_failed; } diff --git a/lib/Object/IRObjectFile.cpp b/lib/Object/IRObjectFile.cpp index ef544aa13b..f20ce6cf66 100644 --- a/lib/Object/IRObjectFile.cpp +++ b/lib/Object/IRObjectFile.cpp @@ -17,14 +17,15 @@ #include "llvm/IR/Mangler.h" #include "llvm/IR/Module.h" #include "llvm/Object/IRObjectFile.h" +#include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/raw_ostream.h" using namespace llvm; using namespace object; -IRObjectFile::IRObjectFile(MemoryBuffer *Object, std::error_code &EC, - LLVMContext &Context) - : SymbolicFile(Binary::ID_IR, Object) { - ErrorOr MOrErr = getLazyBitcodeModule(Object, Context); +IRObjectFile::IRObjectFile(std::unique_ptr Object, + std::error_code &EC, LLVMContext &Context) + : SymbolicFile(Binary::ID_IR, std::move(Object)) { + ErrorOr MOrErr = getLazyBitcodeModule(Data.get(), Context); if ((EC = MOrErr.getError())) return; @@ -153,11 +154,11 @@ basic_symbol_iterator IRObjectFile::symbol_end_impl() const { return basic_symbol_iterator(BasicSymbolRef(Ret, this)); } -ErrorOr -llvm::object::SymbolicFile::createIRObjectFile(MemoryBuffer *Object, - LLVMContext &Context) { +ErrorOr llvm::object::SymbolicFile::createIRObjectFile( + std::unique_ptr Object, LLVMContext &Context) { std::error_code EC; - std::unique_ptr Ret(new IRObjectFile(Object, EC, Context)); + std::unique_ptr Ret( + new IRObjectFile(std::move(Object), EC, Context)); if (EC) return EC; return Ret.release(); diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index 45fc5ea735..09c842c4a0 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -422,9 +422,10 @@ static uint32_t getSectionFlags(const MachOObjectFile *O, return Sect.flags; } -MachOObjectFile::MachOObjectFile(MemoryBuffer *Object, bool IsLittleEndian, - bool Is64bits, std::error_code &EC) - : ObjectFile(getMachOType(IsLittleEndian, Is64bits), Object), +MachOObjectFile::MachOObjectFile(std::unique_ptr Object, + bool IsLittleEndian, bool Is64bits, + std::error_code &EC) + : ObjectFile(getMachOType(IsLittleEndian, Is64bits), std::move(Object)), SymtabLoadCmd(nullptr), DysymtabLoadCmd(nullptr), DataInCodeLoadCmd(nullptr) { uint32_t LoadCommandCount = this->getHeader().ncmds; @@ -1817,13 +1818,13 @@ ObjectFile::createMachOObjectFile(std::unique_ptr &Buffer) { std::error_code EC; std::unique_ptr Ret; if (Magic == "\xFE\xED\xFA\xCE") - Ret.reset(new MachOObjectFile(Buffer.release(), false, false, EC)); + Ret.reset(new MachOObjectFile(std::move(Buffer), false, false, EC)); else if (Magic == "\xCE\xFA\xED\xFE") - Ret.reset(new MachOObjectFile(Buffer.release(), true, false, EC)); + Ret.reset(new MachOObjectFile(std::move(Buffer), true, false, EC)); else if (Magic == "\xFE\xED\xFA\xCF") - Ret.reset(new MachOObjectFile(Buffer.release(), false, true, EC)); + Ret.reset(new MachOObjectFile(std::move(Buffer), false, true, EC)); else if (Magic == "\xCF\xFA\xED\xFE") - Ret.reset(new MachOObjectFile(Buffer.release(), true, true, EC)); + Ret.reset(new MachOObjectFile(std::move(Buffer), true, true, EC)); else return object_error::parse_failed; diff --git a/lib/Object/MachOUniversal.cpp b/lib/Object/MachOUniversal.cpp index 330454ac5a..4ba5d96864 100644 --- a/lib/Object/MachOUniversal.cpp +++ b/lib/Object/MachOUniversal.cpp @@ -86,9 +86,9 @@ std::error_code MachOUniversalBinary::ObjectForArch::getAsArchive( StringRef ParentData = Parent->getData(); StringRef ObjectData = ParentData.substr(Header.offset, Header.size); std::string ObjectName = Parent->getFileName().str(); - MemoryBuffer *ObjBuffer = MemoryBuffer::getMemBuffer( - ObjectData, ObjectName, false); - ErrorOr Obj = Archive::create(ObjBuffer); + std::unique_ptr ObjBuffer( + MemoryBuffer::getMemBuffer(ObjectData, ObjectName, false)); + ErrorOr Obj = Archive::create(std::move(ObjBuffer)); if (std::error_code EC = Obj.getError()) return EC; Result.reset(Obj.get()); @@ -100,19 +100,20 @@ std::error_code MachOUniversalBinary::ObjectForArch::getAsArchive( void MachOUniversalBinary::anchor() { } ErrorOr -MachOUniversalBinary::create(MemoryBuffer *Source) { +MachOUniversalBinary::create(std::unique_ptr Source) { std::error_code EC; std::unique_ptr Ret( - new MachOUniversalBinary(Source, EC)); + new MachOUniversalBinary(std::move(Source), EC)); if (EC) return EC; return Ret.release(); } -MachOUniversalBinary::MachOUniversalBinary(MemoryBuffer *Source, +MachOUniversalBinary::MachOUniversalBinary(std::unique_ptr Source, std::error_code &ec) - : Binary(Binary::ID_MachOUniversalBinary, Source), NumberOfObjects(0) { - if (Source->getBufferSize() < sizeof(MachO::fat_header)) { + : Binary(Binary::ID_MachOUniversalBinary, std::move(Source)), + NumberOfObjects(0) { + if (Data->getBufferSize() < sizeof(MachO::fat_header)) { ec = object_error::invalid_file_type; return; } diff --git a/lib/Object/ObjectFile.cpp b/lib/Object/ObjectFile.cpp index ee2680e6ba..591ed28262 100644 --- a/lib/Object/ObjectFile.cpp +++ b/lib/Object/ObjectFile.cpp @@ -23,8 +23,8 @@ using namespace object; void ObjectFile::anchor() { } -ObjectFile::ObjectFile(unsigned int Type, MemoryBuffer *Source) - : SymbolicFile(Type, Source) {} +ObjectFile::ObjectFile(unsigned int Type, std::unique_ptr Source) + : SymbolicFile(Type, std::move(Source)) {} std::error_code ObjectFile::printSymbolName(raw_ostream &OS, DataRefImpl Symb) const { @@ -77,7 +77,7 @@ ObjectFile::createObjectFile(std::unique_ptr &Object, case sys::fs::file_magic::coff_object: case sys::fs::file_magic::coff_import_library: case sys::fs::file_magic::pecoff_executable: - return createCOFFObjectFile(Object.release()); + return createCOFFObjectFile(std::move(Object)); } llvm_unreachable("Unexpected Object File Type"); } diff --git a/lib/Object/SymbolicFile.cpp b/lib/Object/SymbolicFile.cpp index 46aba3cf05..30cf1a03f4 100644 --- a/lib/Object/SymbolicFile.cpp +++ b/lib/Object/SymbolicFile.cpp @@ -19,8 +19,9 @@ using namespace llvm; using namespace object; -SymbolicFile::SymbolicFile(unsigned int Type, MemoryBuffer *Source) - : Binary(Type, Source) {} +SymbolicFile::SymbolicFile(unsigned int Type, + std::unique_ptr Source) + : Binary(Type, std::move(Source)) {} SymbolicFile::~SymbolicFile() {} @@ -34,7 +35,7 @@ SymbolicFile::createSymbolicFile(std::unique_ptr &Object, switch (Type) { case sys::fs::file_magic::bitcode: if (Context) - return IRObjectFile::createIRObjectFile(Object.release(), *Context); + return IRObjectFile::createIRObjectFile(std::move(Object), *Context); // Fallthrough case sys::fs::file_magic::unknown: case sys::fs::file_magic::archive: diff --git a/tools/lli/lli.cpp b/tools/lli/lli.cpp index 73a19ac667..f69fb435c6 100644 --- a/tools/lli/lli.cpp +++ b/tools/lli/lli.cpp @@ -545,7 +545,7 @@ int main(int argc, char **argv, char * const *envp) { Err.print(argv[0], errs()); return 1; } - object::Archive *Ar = new object::Archive(ArBuf.release(), ec); + object::Archive *Ar = new object::Archive(std::move(ArBuf), ec); if (ec || !Ar) { Err.print(argv[0], errs()); return 1; diff --git a/tools/llvm-ar/llvm-ar.cpp b/tools/llvm-ar/llvm-ar.cpp index 3ca1a91074..60886bb7b1 100644 --- a/tools/llvm-ar/llvm-ar.cpp +++ b/tools/llvm-ar/llvm-ar.cpp @@ -938,7 +938,7 @@ static int performOperation(ArchiveOperation Operation) { } if (!EC) { - object::Archive Archive(Buf.release(), EC); + object::Archive Archive(std::move(Buf), EC); if (EC) { errs() << ToolName << ": error loading '" << ArchiveName -- cgit v1.2.3