[llvm] r211595 - Pass a unique_ptr<MemoryBuffer> to the constructors in the Binary hierarchy.
Rafael Espindola
rafael.espindola at gmail.com
Tue Jun 24 06:56:32 PDT 2014
Author: rafael
Date: Tue Jun 24 08:56:32 2014
New Revision: 211595
URL: http://llvm.org/viewvc/llvm-project?rev=211595&view=rev
Log:
Pass a unique_ptr<MemoryBuffer> to the constructors in the Binary hierarchy.
Once the objects are constructed, they own the buffer. Passing a unique_ptr
makes that clear.
Modified:
llvm/trunk/include/llvm/Object/Archive.h
llvm/trunk/include/llvm/Object/Binary.h
llvm/trunk/include/llvm/Object/COFF.h
llvm/trunk/include/llvm/Object/ELFObjectFile.h
llvm/trunk/include/llvm/Object/IRObjectFile.h
llvm/trunk/include/llvm/Object/MachO.h
llvm/trunk/include/llvm/Object/MachOUniversal.h
llvm/trunk/include/llvm/Object/ObjectFile.h
llvm/trunk/include/llvm/Object/SymbolicFile.h
llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
llvm/trunk/lib/Object/Archive.cpp
llvm/trunk/lib/Object/Binary.cpp
llvm/trunk/lib/Object/COFFObjectFile.cpp
llvm/trunk/lib/Object/ELFObjectFile.cpp
llvm/trunk/lib/Object/IRObjectFile.cpp
llvm/trunk/lib/Object/MachOObjectFile.cpp
llvm/trunk/lib/Object/MachOUniversal.cpp
llvm/trunk/lib/Object/ObjectFile.cpp
llvm/trunk/lib/Object/SymbolicFile.cpp
llvm/trunk/tools/lli/lli.cpp
llvm/trunk/tools/llvm-ar/llvm-ar.cpp
Modified: llvm/trunk/include/llvm/Object/Archive.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/Archive.h?rev=211595&r1=211594&r2=211595&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/Archive.h (original)
+++ llvm/trunk/include/llvm/Object/Archive.h Tue Jun 24 08:56:32 2014
@@ -164,8 +164,8 @@ public:
}
};
- Archive(MemoryBuffer *source, std::error_code &ec);
- static ErrorOr<Archive *> create(MemoryBuffer *Source);
+ Archive(std::unique_ptr<MemoryBuffer> Source, std::error_code &EC);
+ static ErrorOr<Archive *> create(std::unique_ptr<MemoryBuffer> Source);
enum Kind {
K_GNU,
Modified: llvm/trunk/include/llvm/Object/Binary.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/Binary.h?rev=211595&r1=211594&r2=211595&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/Binary.h (original)
+++ llvm/trunk/include/llvm/Object/Binary.h Tue Jun 24 08:56:32 2014
@@ -36,7 +36,7 @@ private:
protected:
std::unique_ptr<MemoryBuffer> Data;
- Binary(unsigned int Type, MemoryBuffer *Source);
+ Binary(unsigned int Type, std::unique_ptr<MemoryBuffer> Source);
enum {
ID_Archive,
Modified: llvm/trunk/include/llvm/Object/COFF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/COFF.h?rev=211595&r1=211594&r2=211595&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/COFF.h (original)
+++ llvm/trunk/include/llvm/Object/COFF.h Tue Jun 24 08:56:32 2014
@@ -420,7 +420,7 @@ protected:
StringRef &Result) const override;
public:
- COFFObjectFile(MemoryBuffer *Object, std::error_code &EC);
+ COFFObjectFile(std::unique_ptr<MemoryBuffer> 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;
Modified: llvm/trunk/include/llvm/Object/ELFObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELFObjectFile.h?rev=211595&r1=211594&r2=211595&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELFObjectFile.h (original)
+++ llvm/trunk/include/llvm/Object/ELFObjectFile.h Tue Jun 24 08:56:32 2014
@@ -177,7 +177,7 @@ protected:
bool isDyldELFObject;
public:
- ELFObjectFile(MemoryBuffer *Object, std::error_code &EC);
+ ELFObjectFile(std::unique_ptr<MemoryBuffer> Object, std::error_code &EC);
const Elf_Sym *getSymbol(DataRefImpl Symb) const;
@@ -773,12 +773,13 @@ ELFObjectFile<ELFT>::getRela(DataRefImpl
}
template <class ELFT>
-ELFObjectFile<ELFT>::ELFObjectFile(MemoryBuffer *Object, std::error_code &ec)
+ELFObjectFile<ELFT>::ELFObjectFile(std::unique_ptr<MemoryBuffer> Object,
+ std::error_code &EC)
: ObjectFile(getELFType(static_cast<endianness>(ELFT::TargetEndianness) ==
support::little,
ELFT::Is64Bits),
- Object),
- EF(Object, ec) {}
+ std::move(Object)),
+ EF(Data.get(), EC) {}
template <class ELFT>
basic_symbol_iterator ELFObjectFile<ELFT>::symbol_begin_impl() const {
Modified: llvm/trunk/include/llvm/Object/IRObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/IRObjectFile.h?rev=211595&r1=211594&r2=211595&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/IRObjectFile.h (original)
+++ llvm/trunk/include/llvm/Object/IRObjectFile.h Tue Jun 24 08:56:32 2014
@@ -27,7 +27,8 @@ class IRObjectFile : public SymbolicFile
std::unique_ptr<Mangler> Mang;
public:
- IRObjectFile(MemoryBuffer *Object, std::error_code &EC, LLVMContext &Context);
+ IRObjectFile(std::unique_ptr<MemoryBuffer> Object, std::error_code &EC,
+ LLVMContext &Context);
~IRObjectFile();
void moveSymbolNext(DataRefImpl &Symb) const override;
std::error_code printSymbolName(raw_ostream &OS,
Modified: llvm/trunk/include/llvm/Object/MachO.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/MachO.h?rev=211595&r1=211594&r2=211595&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/MachO.h (original)
+++ llvm/trunk/include/llvm/Object/MachO.h Tue Jun 24 08:56:32 2014
@@ -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<MemoryBuffer> Object, bool IsLittleEndian,
+ bool Is64Bits, std::error_code &EC);
void moveSymbolNext(DataRefImpl &Symb) const override;
std::error_code getSymbolName(DataRefImpl Symb,
Modified: llvm/trunk/include/llvm/Object/MachOUniversal.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/MachOUniversal.h?rev=211595&r1=211594&r2=211595&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/MachOUniversal.h (original)
+++ llvm/trunk/include/llvm/Object/MachOUniversal.h Tue Jun 24 08:56:32 2014
@@ -83,8 +83,10 @@ public:
}
};
- MachOUniversalBinary(MemoryBuffer *Source, std::error_code &ec);
- static ErrorOr<MachOUniversalBinary*> create(MemoryBuffer *Source);
+ MachOUniversalBinary(std::unique_ptr<MemoryBuffer> Source,
+ std::error_code &ec);
+ static ErrorOr<MachOUniversalBinary *>
+ create(std::unique_ptr<MemoryBuffer> Source);
object_iterator begin_objects() const {
return ObjectForArch(this, 0);
Modified: llvm/trunk/include/llvm/Object/ObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ObjectFile.h?rev=211595&r1=211594&r2=211595&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ObjectFile.h (original)
+++ llvm/trunk/include/llvm/Object/ObjectFile.h Tue Jun 24 08:56:32 2014
@@ -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<MemoryBuffer> Source);
const uint8_t *base() const {
return reinterpret_cast<const uint8_t *>(Data->getBufferStart());
@@ -347,7 +347,8 @@ public:
}
public:
- static ErrorOr<ObjectFile *> createCOFFObjectFile(MemoryBuffer *Object);
+ static ErrorOr<ObjectFile *>
+ createCOFFObjectFile(std::unique_ptr<MemoryBuffer> Object);
static ErrorOr<ObjectFile *>
createELFObjectFile(std::unique_ptr<MemoryBuffer> &Object);
static ErrorOr<ObjectFile *>
Modified: llvm/trunk/include/llvm/Object/SymbolicFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/SymbolicFile.h?rev=211595&r1=211594&r2=211595&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/SymbolicFile.h (original)
+++ llvm/trunk/include/llvm/Object/SymbolicFile.h Tue Jun 24 08:56:32 2014
@@ -115,7 +115,7 @@ const uint64_t UnknownAddressOrSize = ~0
class SymbolicFile : public Binary {
public:
virtual ~SymbolicFile();
- SymbolicFile(unsigned int Type, MemoryBuffer *Source);
+ SymbolicFile(unsigned int Type, std::unique_ptr<MemoryBuffer> Source);
// virtual interface.
virtual void moveSymbolNext(DataRefImpl &Symb) const = 0;
@@ -142,8 +142,9 @@ public:
}
// construction aux.
- static ErrorOr<SymbolicFile *> createIRObjectFile(MemoryBuffer *Object,
- LLVMContext &Context);
+ static ErrorOr<SymbolicFile *>
+ createIRObjectFile(std::unique_ptr<MemoryBuffer> Object,
+ LLVMContext &Context);
static ErrorOr<SymbolicFile *>
createSymbolicFile(std::unique_ptr<MemoryBuffer> &Object,
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp?rev=211595&r1=211594&r2=211595&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp Tue Jun 24 08:56:32 2014
@@ -55,9 +55,9 @@ template <class ELFT> class DyldELFObjec
public:
DyldELFObject(std::unique_ptr<ObjectFile> UnderlyingFile,
- MemoryBuffer *Wrapper, std::error_code &ec);
+ std::unique_ptr<MemoryBuffer> Wrapper, std::error_code &ec);
- DyldELFObject(MemoryBuffer *Wrapper, std::error_code &ec);
+ DyldELFObject(std::unique_ptr<MemoryBuffer> 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 <class ELFT>
-DyldELFObject<ELFT>::DyldELFObject(MemoryBuffer *Wrapper, std::error_code &ec)
- : ELFObjectFile<ELFT>(Wrapper, ec) {
+DyldELFObject<ELFT>::DyldELFObject(std::unique_ptr<MemoryBuffer> Wrapper,
+ std::error_code &EC)
+ : ELFObjectFile<ELFT>(std::move(Wrapper), EC) {
this->isDyldELFObject = true;
}
template <class ELFT>
DyldELFObject<ELFT>::DyldELFObject(std::unique_ptr<ObjectFile> UnderlyingFile,
- MemoryBuffer *Wrapper, std::error_code &ec)
- : ELFObjectFile<ELFT>(Wrapper, ec),
+ std::unique_ptr<MemoryBuffer> Wrapper,
+ std::error_code &EC)
+ : ELFObjectFile<ELFT>(std::move(Wrapper), EC),
UnderlyingFile(std::move(UnderlyingFile)) {
this->isDyldELFObject = true;
}
@@ -183,29 +185,29 @@ RuntimeDyldELF::createObjectImageFromFil
return nullptr;
std::error_code ec;
- MemoryBuffer *Buffer =
- MemoryBuffer::getMemBuffer(ObjFile->getData(), "", false);
+ std::unique_ptr<MemoryBuffer> Buffer(
+ MemoryBuffer::getMemBuffer(ObjFile->getData(), "", false));
if (ObjFile->getBytesInAddress() == 4 && ObjFile->isLittleEndian()) {
auto Obj =
llvm::make_unique<DyldELFObject<ELFType<support::little, 2, false>>>(
- std::move(ObjFile), Buffer, ec);
+ std::move(ObjFile), std::move(Buffer), ec);
return new ELFObjectImage<ELFType<support::little, 2, false>>(
nullptr, std::move(Obj));
} else if (ObjFile->getBytesInAddress() == 4 && !ObjFile->isLittleEndian()) {
auto Obj =
llvm::make_unique<DyldELFObject<ELFType<support::big, 2, false>>>(
- std::move(ObjFile), Buffer, ec);
+ std::move(ObjFile), std::move(Buffer), ec);
return new ELFObjectImage<ELFType<support::big, 2, false>>(nullptr, std::move(Obj));
} else if (ObjFile->getBytesInAddress() == 8 && !ObjFile->isLittleEndian()) {
auto Obj = llvm::make_unique<DyldELFObject<ELFType<support::big, 2, true>>>(
- std::move(ObjFile), Buffer, ec);
+ std::move(ObjFile), std::move(Buffer), ec);
return new ELFObjectImage<ELFType<support::big, 2, true>>(nullptr,
std::move(Obj));
} else if (ObjFile->getBytesInAddress() == 8 && ObjFile->isLittleEndian()) {
auto Obj =
llvm::make_unique<DyldELFObject<ELFType<support::little, 2, true>>>(
- std::move(ObjFile), Buffer, ec);
+ std::move(ObjFile), std::move(Buffer), ec);
return new ELFObjectImage<ELFType<support::little, 2, true>>(
nullptr, std::move(Obj));
} else
@@ -220,29 +222,31 @@ ObjectImage *RuntimeDyldELF::createObjec
(uint8_t)Buffer->getBufferStart()[ELF::EI_DATA]);
std::error_code ec;
+ std::unique_ptr<MemoryBuffer> Buf(Buffer->getMemBuffer());
+
if (Ident.first == ELF::ELFCLASS32 && Ident.second == ELF::ELFDATA2LSB) {
auto Obj =
llvm::make_unique<DyldELFObject<ELFType<support::little, 4, false>>>(
- Buffer->getMemBuffer(), ec);
+ std::move(Buf), ec);
return new ELFObjectImage<ELFType<support::little, 4, false>>(
Buffer, std::move(Obj));
} else if (Ident.first == ELF::ELFCLASS32 &&
Ident.second == ELF::ELFDATA2MSB) {
auto Obj =
llvm::make_unique<DyldELFObject<ELFType<support::big, 4, false>>>(
- Buffer->getMemBuffer(), ec);
+ std::move(Buf), ec);
return new ELFObjectImage<ELFType<support::big, 4, false>>(Buffer,
std::move(Obj));
} else if (Ident.first == ELF::ELFCLASS64 &&
Ident.second == ELF::ELFDATA2MSB) {
auto Obj = llvm::make_unique<DyldELFObject<ELFType<support::big, 8, true>>>(
- Buffer->getMemBuffer(), ec);
+ std::move(Buf), ec);
return new ELFObjectImage<ELFType<support::big, 8, true>>(Buffer, std::move(Obj));
} else if (Ident.first == ELF::ELFCLASS64 &&
Ident.second == ELF::ELFDATA2LSB) {
auto Obj =
llvm::make_unique<DyldELFObject<ELFType<support::little, 8, true>>>(
- Buffer->getMemBuffer(), ec);
+ std::move(Buf), ec);
return new ELFObjectImage<ELFType<support::little, 8, true>>(Buffer, std::move(Obj));
} else
llvm_unreachable("Unexpected ELF format");
Modified: llvm/trunk/lib/Object/Archive.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/Archive.cpp?rev=211595&r1=211594&r2=211595&view=diff
==============================================================================
--- llvm/trunk/lib/Object/Archive.cpp (original)
+++ llvm/trunk/lib/Object/Archive.cpp Tue Jun 24 08:56:32 2014
@@ -186,20 +186,19 @@ Archive::Child::getAsBinary(LLVMContext
return createBinary(Buff, Context);
}
-ErrorOr<Archive*> Archive::create(MemoryBuffer *Source) {
+ErrorOr<Archive *> Archive::create(std::unique_ptr<MemoryBuffer> Source) {
std::error_code EC;
- std::unique_ptr<Archive> Ret(new Archive(Source, EC));
+ std::unique_ptr<Archive> 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<MemoryBuffer> 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;
}
Modified: llvm/trunk/lib/Object/Binary.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/Binary.cpp?rev=211595&r1=211594&r2=211595&view=diff
==============================================================================
--- llvm/trunk/lib/Object/Binary.cpp (original)
+++ llvm/trunk/lib/Object/Binary.cpp Tue Jun 24 08:56:32 2014
@@ -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<MemoryBuffer> Source)
+ : TypeID(Type), Data(std::move(Source)) {}
StringRef Binary::getData() const {
return Data->getBuffer();
@@ -44,7 +44,7 @@ ErrorOr<Binary *> object::createBinary(s
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<Binary *> object::createBinary(s
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.
Modified: llvm/trunk/lib/Object/COFFObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/COFFObjectFile.cpp?rev=211595&r1=211594&r2=211595&view=diff
==============================================================================
--- llvm/trunk/lib/Object/COFFObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/COFFObjectFile.cpp Tue Jun 24 08:56:32 2014
@@ -511,8 +511,9 @@ std::error_code COFFObjectFile::initExpo
return object_error::success;
}
-COFFObjectFile::COFFObjectFile(MemoryBuffer *Object, std::error_code &EC)
- : ObjectFile(Binary::ID_COFF, Object), COFFHeader(nullptr),
+COFFObjectFile::COFFObjectFile(std::unique_ptr<MemoryBuffer> 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(S
return object_error::success;
}
-ErrorOr<ObjectFile *> ObjectFile::createCOFFObjectFile(MemoryBuffer *Object) {
+ErrorOr<ObjectFile *>
+ObjectFile::createCOFFObjectFile(std::unique_ptr<MemoryBuffer> Object) {
std::error_code EC;
- std::unique_ptr<COFFObjectFile> Ret(new COFFObjectFile(Object, EC));
+ std::unique_ptr<COFFObjectFile> Ret(
+ new COFFObjectFile(std::move(Object), EC));
if (EC)
return EC;
return Ret.release();
Modified: llvm/trunk/lib/Object/ELFObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/ELFObjectFile.cpp?rev=211595&r1=211594&r2=211595&view=diff
==============================================================================
--- llvm/trunk/lib/Object/ELFObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/ELFObjectFile.cpp Tue Jun 24 08:56:32 2014
@@ -34,7 +34,7 @@ ObjectFile::createELFObjectFile(std::uni
#endif
if (MaxAlignment >= 2)
R.reset(new ELFObjectFile<ELFType<support::little, 2, false>>(
- 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::uni
else
#endif
if (MaxAlignment >= 2)
- R.reset(new ELFObjectFile<ELFType<support::big, 2, false>>(Obj.release(),
+ R.reset(new ELFObjectFile<ELFType<support::big, 2, false>>(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<ELFType<support::big, 8, true>>(Obj.release(), EC));
+ R.reset(new ELFObjectFile<ELFType<support::big, 8, true>>(std::move(Obj),
+ EC));
else
#endif
if (MaxAlignment >= 2)
- R.reset(
- new ELFObjectFile<ELFType<support::big, 2, true>>(Obj.release(), EC));
+ R.reset(new ELFObjectFile<ELFType<support::big, 2, true>>(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<ELFType<support::little, 8, true>>(
- Obj.release(), EC));
+ std::move(Obj), EC));
else
#endif
if (MaxAlignment >= 2)
R.reset(new ELFObjectFile<ELFType<support::little, 2, true>>(
- Obj.release(), EC));
+ std::move(Obj), EC));
else
return object_error::parse_failed;
}
Modified: llvm/trunk/lib/Object/IRObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/IRObjectFile.cpp?rev=211595&r1=211594&r2=211595&view=diff
==============================================================================
--- llvm/trunk/lib/Object/IRObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/IRObjectFile.cpp Tue Jun 24 08:56:32 2014
@@ -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<Module *> MOrErr = getLazyBitcodeModule(Object, Context);
+IRObjectFile::IRObjectFile(std::unique_ptr<MemoryBuffer> Object,
+ std::error_code &EC, LLVMContext &Context)
+ : SymbolicFile(Binary::ID_IR, std::move(Object)) {
+ ErrorOr<Module *> MOrErr = getLazyBitcodeModule(Data.get(), Context);
if ((EC = MOrErr.getError()))
return;
@@ -153,11 +154,11 @@ basic_symbol_iterator IRObjectFile::symb
return basic_symbol_iterator(BasicSymbolRef(Ret, this));
}
-ErrorOr<SymbolicFile *>
-llvm::object::SymbolicFile::createIRObjectFile(MemoryBuffer *Object,
- LLVMContext &Context) {
+ErrorOr<SymbolicFile *> llvm::object::SymbolicFile::createIRObjectFile(
+ std::unique_ptr<MemoryBuffer> Object, LLVMContext &Context) {
std::error_code EC;
- std::unique_ptr<IRObjectFile> Ret(new IRObjectFile(Object, EC, Context));
+ std::unique_ptr<IRObjectFile> Ret(
+ new IRObjectFile(std::move(Object), EC, Context));
if (EC)
return EC;
return Ret.release();
Modified: llvm/trunk/lib/Object/MachOObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/MachOObjectFile.cpp?rev=211595&r1=211594&r2=211595&view=diff
==============================================================================
--- llvm/trunk/lib/Object/MachOObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/MachOObjectFile.cpp Tue Jun 24 08:56:32 2014
@@ -422,9 +422,10 @@ static uint32_t getSectionFlags(const Ma
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<MemoryBuffer> 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::u
std::error_code EC;
std::unique_ptr<MachOObjectFile> 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;
Modified: llvm/trunk/lib/Object/MachOUniversal.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/MachOUniversal.cpp?rev=211595&r1=211594&r2=211595&view=diff
==============================================================================
--- llvm/trunk/lib/Object/MachOUniversal.cpp (original)
+++ llvm/trunk/lib/Object/MachOUniversal.cpp Tue Jun 24 08:56:32 2014
@@ -86,9 +86,9 @@ std::error_code MachOUniversalBinary::Ob
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<Archive *> Obj = Archive::create(ObjBuffer);
+ std::unique_ptr<MemoryBuffer> ObjBuffer(
+ MemoryBuffer::getMemBuffer(ObjectData, ObjectName, false));
+ ErrorOr<Archive *> 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::Ob
void MachOUniversalBinary::anchor() { }
ErrorOr<MachOUniversalBinary *>
-MachOUniversalBinary::create(MemoryBuffer *Source) {
+MachOUniversalBinary::create(std::unique_ptr<MemoryBuffer> Source) {
std::error_code EC;
std::unique_ptr<MachOUniversalBinary> 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<MemoryBuffer> 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;
}
Modified: llvm/trunk/lib/Object/ObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/ObjectFile.cpp?rev=211595&r1=211594&r2=211595&view=diff
==============================================================================
--- llvm/trunk/lib/Object/ObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/ObjectFile.cpp Tue Jun 24 08:56:32 2014
@@ -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<MemoryBuffer> 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
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");
}
Modified: llvm/trunk/lib/Object/SymbolicFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/SymbolicFile.cpp?rev=211595&r1=211594&r2=211595&view=diff
==============================================================================
--- llvm/trunk/lib/Object/SymbolicFile.cpp (original)
+++ llvm/trunk/lib/Object/SymbolicFile.cpp Tue Jun 24 08:56:32 2014
@@ -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<MemoryBuffer> Source)
+ : Binary(Type, std::move(Source)) {}
SymbolicFile::~SymbolicFile() {}
@@ -34,7 +35,7 @@ SymbolicFile::createSymbolicFile(std::un
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:
Modified: llvm/trunk/tools/lli/lli.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lli/lli.cpp?rev=211595&r1=211594&r2=211595&view=diff
==============================================================================
--- llvm/trunk/tools/lli/lli.cpp (original)
+++ llvm/trunk/tools/lli/lli.cpp Tue Jun 24 08:56:32 2014
@@ -545,7 +545,7 @@ int main(int argc, char **argv, char * c
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;
Modified: llvm/trunk/tools/llvm-ar/llvm-ar.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ar/llvm-ar.cpp?rev=211595&r1=211594&r2=211595&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-ar/llvm-ar.cpp (original)
+++ llvm/trunk/tools/llvm-ar/llvm-ar.cpp Tue Jun 24 08:56:32 2014
@@ -938,7 +938,7 @@ static int performOperation(ArchiveOpera
}
if (!EC) {
- object::Archive Archive(Buf.release(), EC);
+ object::Archive Archive(std::move(Buf), EC);
if (EC) {
errs() << ToolName << ": error loading '" << ArchiveName
More information about the llvm-commits
mailing list