[llvm] r214377 - Use std::unique_ptr to make the ownership explicit.
David Blaikie
dblaikie at gmail.com
Thu Jul 31 11:57:18 PDT 2014
On Wed, Jul 30, 2014 at 8:12 PM, Rafael Espindola
<rafael.espindola at gmail.com> wrote:
> Author: rafael
> Date: Wed Jul 30 22:12:45 2014
> New Revision: 214377
>
> URL: http://llvm.org/viewvc/llvm-project?rev=214377&view=rev
> Log:
> Use std::unique_ptr to make the ownership explicit.
Hooray! \o/
> Modified:
> llvm/trunk/include/llvm/Object/Binary.h
> llvm/trunk/include/llvm/Object/ObjectFile.h
> llvm/trunk/include/llvm/Object/SymbolicFile.h
> llvm/trunk/lib/DebugInfo/DWARFUnit.cpp
> llvm/trunk/lib/ExecutionEngine/RuntimeDyld/ObjectImageCommon.h
> llvm/trunk/lib/Object/Binary.cpp
> llvm/trunk/lib/Object/COFFObjectFile.cpp
> llvm/trunk/lib/Object/ELFObjectFile.cpp
> llvm/trunk/lib/Object/MachOObjectFile.cpp
> llvm/trunk/lib/Object/Object.cpp
> llvm/trunk/lib/Object/ObjectFile.cpp
> llvm/trunk/lib/Object/SymbolicFile.cpp
> llvm/trunk/lib/ProfileData/CoverageMappingReader.cpp
> llvm/trunk/tools/lli/lli.cpp
> llvm/trunk/tools/llvm-ar/llvm-ar.cpp
> llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
> llvm/trunk/tools/llvm-nm/llvm-nm.cpp
> llvm/trunk/tools/llvm-objdump/MachODump.cpp
> llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
> llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp
> llvm/trunk/tools/llvm-size/llvm-size.cpp
> llvm/trunk/tools/llvm-symbolizer/LLVMSymbolize.cpp
> llvm/trunk/tools/llvm-vtabledump/llvm-vtabledump.cpp
> llvm/trunk/tools/macho-dump/macho-dump.cpp
> llvm/trunk/tools/obj2yaml/obj2yaml.cpp
>
> Modified: llvm/trunk/include/llvm/Object/Binary.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/Binary.h?rev=214377&r1=214376&r2=214377&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Object/Binary.h (original)
> +++ llvm/trunk/include/llvm/Object/Binary.h Wed Jul 30 22:12:45 2014
> @@ -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<Binary *> createBinary(std::unique_ptr<MemoryBuffer> Source,
> - LLVMContext *Context = nullptr);
> +ErrorOr<std::unique_ptr<Binary>>
> +createBinary(std::unique_ptr<MemoryBuffer> Source,
> + LLVMContext *Context = nullptr);
>
> -ErrorOr<Binary *> createBinary(StringRef Path);
> +ErrorOr<std::unique_ptr<Binary>> createBinary(StringRef Path);
> }
> }
>
>
> Modified: llvm/trunk/include/llvm/Object/ObjectFile.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ObjectFile.h?rev=214377&r1=214376&r2=214377&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Object/ObjectFile.h (original)
> +++ llvm/trunk/include/llvm/Object/ObjectFile.h Wed Jul 30 22:12:45 2014
> @@ -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<ObjectFile *> createObjectFile(StringRef ObjectPath);
> - static ErrorOr<ObjectFile *>
> + static ErrorOr<std::unique_ptr<ObjectFile>>
> + createObjectFile(StringRef ObjectPath);
> +
> + static ErrorOr<std::unique_ptr<ObjectFile>>
> createObjectFile(std::unique_ptr<MemoryBuffer> &Object,
> sys::fs::file_magic Type);
> - static ErrorOr<ObjectFile *>
> + static ErrorOr<std::unique_ptr<ObjectFile>>
> createObjectFile(std::unique_ptr<MemoryBuffer> &Object) {
> return createObjectFile(Object, sys::fs::file_magic::unknown);
> }
> @@ -358,11 +362,13 @@ public:
> }
>
> public:
> - static ErrorOr<ObjectFile *>
> + static ErrorOr<std::unique_ptr<COFFObjectFile>>
> createCOFFObjectFile(std::unique_ptr<MemoryBuffer> Object);
> - static ErrorOr<ObjectFile *>
> +
> + static ErrorOr<std::unique_ptr<ObjectFile>>
> createELFObjectFile(std::unique_ptr<MemoryBuffer> &Object);
> - static ErrorOr<ObjectFile *>
> +
> + static ErrorOr<std::unique_ptr<MachOObjectFile>>
> createMachOObjectFile(std::unique_ptr<MemoryBuffer> &Object);
> };
>
>
> Modified: llvm/trunk/include/llvm/Object/SymbolicFile.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/SymbolicFile.h?rev=214377&r1=214376&r2=214377&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Object/SymbolicFile.h (original)
> +++ llvm/trunk/include/llvm/Object/SymbolicFile.h Wed Jul 30 22:12:45 2014
> @@ -142,15 +142,16 @@ public:
> }
>
> // construction aux.
> - static ErrorOr<SymbolicFile *>
> + static ErrorOr<std::unique_ptr<SymbolicFile>>
> createSymbolicFile(std::unique_ptr<MemoryBuffer> &Object,
> sys::fs::file_magic Type, LLVMContext *Context);
>
> - static ErrorOr<SymbolicFile *>
> + static ErrorOr<std::unique_ptr<SymbolicFile>>
> createSymbolicFile(std::unique_ptr<MemoryBuffer> &Object) {
> return createSymbolicFile(Object, sys::fs::file_magic::unknown, nullptr);
> }
> - static ErrorOr<SymbolicFile *> createSymbolicFile(StringRef ObjectPath);
> + static ErrorOr<std::unique_ptr<SymbolicFile>>
> + createSymbolicFile(StringRef ObjectPath);
>
> static inline bool classof(const Binary *v) {
> return v->isSymbolic();
>
> Modified: llvm/trunk/lib/DebugInfo/DWARFUnit.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFUnit.cpp?rev=214377&r1=214376&r2=214377&view=diff
> ==============================================================================
> --- llvm/trunk/lib/DebugInfo/DWARFUnit.cpp (original)
> +++ llvm/trunk/lib/DebugInfo/DWARFUnit.cpp Wed Jul 30 22:12:45 2014
> @@ -260,12 +260,12 @@ bool DWARFUnit::parseDWO() {
> sys::path::append(AbsolutePath, CompilationDir);
> }
> sys::path::append(AbsolutePath, DWOFileName);
> - ErrorOr<object::ObjectFile *> DWOFile =
> + ErrorOr<std::unique_ptr<object::ObjectFile>> DWOFile =
> object::ObjectFile::createObjectFile(AbsolutePath);
Judging by this patch I would assume this was previously leaking
memory (since the patch doesn't remove any "delete" or taking ownershp
from the raw pointer to some unique_ptr, etc)
> if (!DWOFile)
> return false;
> // Reset DWOHolder.
> - DWO.reset(new DWOHolder(DWOFile.get()));
> + DWO.reset(new DWOHolder(DWOFile.get().get()));
But looking at DWOHolder's ctor, it seems it was taking ownership,
just via raw pointer - so your change is probably now causing a double
delete. DWOHolder's ctor should take a unique_ptr by value, std::move
into its DWOFile unique_ptr member, and this call site should be
DWOHolder(std::move(DWOFile.get())) or DWOHolder(std::move(*DWOFile)).
(also, I'd be inclined to change "DWO.reset(new DWOHolder" to "DWO =
llvm::make_unique<DWOHolder>")
How do you feel about using the pointer-like operations in ErrorOr? In
this case that would be "DWOFile->get()" rather than
"DWOFile.get().get()". There's many other cases where ErrorOr's op* or
op-> could be used in this change - I won't call each one out
separately.
Also, (m)any cases where we need to pass some_unique_ptr.get() I see
that as a great opportunity to use a reference parameter instead of a
pointer parameter and just pass "*some_unique_ptr" - if the API is
changed first, it actually makes the unique_ptr cleanup less invasive,
since the usage is *ptr before and after the change. (in this case
it'd be either "**DWOFile" or "*DWOFile.get()" if the function took a
reference)
> DWARFUnit *DWOCU = DWO->getUnit();
> // Verify that compile unit in .dwo file is valid.
> if (!DWOCU || DWOCU->getDWOId() != getDWOId()) {
>
> Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/ObjectImageCommon.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/ObjectImageCommon.h?rev=214377&r1=214376&r2=214377&view=diff
> ==============================================================================
> --- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/ObjectImageCommon.h (original)
> +++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/ObjectImageCommon.h Wed Jul 30 22:12:45 2014
> @@ -49,7 +49,7 @@ public:
> // FIXME: error checking? createObjectFile returns an ErrorOr<ObjectFile*>
> // and should probably be checked for failure.
> std::unique_ptr<MemoryBuffer> Buf(Buffer->getMemBuffer());
> - ObjFile.reset(object::ObjectFile::createObjectFile(Buf).get());
> + ObjFile = std::move(object::ObjectFile::createObjectFile(Buf).get());
> }
> ObjectImageCommon(std::unique_ptr<object::ObjectFile> Input)
> : ObjectImage(nullptr), ObjFile(std::move(Input)) {}
>
> Modified: llvm/trunk/lib/Object/Binary.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/Binary.cpp?rev=214377&r1=214376&r2=214377&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Object/Binary.cpp (original)
> +++ llvm/trunk/lib/Object/Binary.cpp Wed Jul 30 22:12:45 2014
> @@ -38,8 +38,9 @@ StringRef Binary::getFileName() const {
> return Data->getBufferIdentifier();
> }
>
> -ErrorOr<Binary *> object::createBinary(std::unique_ptr<MemoryBuffer> Buffer,
> - LLVMContext *Context) {
> +ErrorOr<std::unique_ptr<Binary>>
> +object::createBinary(std::unique_ptr<MemoryBuffer> Buffer,
> + LLVMContext *Context) {
> sys::fs::file_magic Type = sys::fs::identify_magic(Buffer->getBuffer());
>
> switch (Type) {
> @@ -74,7 +75,7 @@ ErrorOr<Binary *> object::createBinary(s
> llvm_unreachable("Unexpected Binary File Type");
> }
>
> -ErrorOr<Binary *> object::createBinary(StringRef Path) {
> +ErrorOr<std::unique_ptr<Binary>> object::createBinary(StringRef Path) {
> ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
> MemoryBuffer::getFileOrSTDIN(Path);
> if (std::error_code EC = FileOrErr.getError())
>
> Modified: llvm/trunk/lib/Object/COFFObjectFile.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/COFFObjectFile.cpp?rev=214377&r1=214376&r2=214377&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Object/COFFObjectFile.cpp (original)
> +++ llvm/trunk/lib/Object/COFFObjectFile.cpp Wed Jul 30 22:12:45 2014
> @@ -1112,12 +1112,12 @@ ExportDirectoryEntryRef::getSymbolName(S
> return object_error::success;
> }
>
> -ErrorOr<ObjectFile *>
> +ErrorOr<std::unique_ptr<COFFObjectFile>>
> ObjectFile::createCOFFObjectFile(std::unique_ptr<MemoryBuffer> Object) {
> std::error_code EC;
> std::unique_ptr<COFFObjectFile> Ret(
> new COFFObjectFile(std::move(Object), EC));
> if (EC)
> return EC;
> - return Ret.release();
> + return std::move(Ret);
This std::move is unnecessary (since it's a local variable) and can
inhibit NRVO.
> }
>
> Modified: llvm/trunk/lib/Object/ELFObjectFile.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/ELFObjectFile.cpp?rev=214377&r1=214376&r2=214377&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Object/ELFObjectFile.cpp (original)
> +++ llvm/trunk/lib/Object/ELFObjectFile.cpp Wed Jul 30 22:12:45 2014
> @@ -17,7 +17,7 @@
> namespace llvm {
> using namespace object;
>
> -ErrorOr<ObjectFile *>
> +ErrorOr<std::unique_ptr<ObjectFile>>
> ObjectFile::createELFObjectFile(std::unique_ptr<MemoryBuffer> &Obj) {
> std::pair<unsigned char, unsigned char> Ident =
> getElfArchType(Obj->getBuffer());
> @@ -80,7 +80,7 @@ ObjectFile::createELFObjectFile(std::uni
>
> if (EC)
> return EC;
> - return R.release();
> + return std::move(R);
Another unnecessary/pessimizing std::move.
> }
>
> } // end namespace llvm
>
> Modified: llvm/trunk/lib/Object/MachOObjectFile.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/MachOObjectFile.cpp?rev=214377&r1=214376&r2=214377&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Object/MachOObjectFile.cpp (original)
> +++ llvm/trunk/lib/Object/MachOObjectFile.cpp Wed Jul 30 22:12:45 2014
> @@ -1721,7 +1721,7 @@ void MachOObjectFile::ReadULEB128s(uint6
> }
> }
>
> -ErrorOr<ObjectFile *>
> +ErrorOr<std::unique_ptr<MachOObjectFile>>
> ObjectFile::createMachOObjectFile(std::unique_ptr<MemoryBuffer> &Buffer) {
> StringRef Magic = Buffer->getBuffer().slice(0, 4);
> std::error_code EC;
> @@ -1739,6 +1739,6 @@ ObjectFile::createMachOObjectFile(std::u
>
> if (EC)
> return EC;
> - return Ret.release();
> + return std::move(Ret);
& another.
> }
>
>
> Modified: llvm/trunk/lib/Object/Object.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/Object.cpp?rev=214377&r1=214376&r2=214377&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Object/Object.cpp (original)
> +++ llvm/trunk/lib/Object/Object.cpp Wed Jul 30 22:12:45 2014
> @@ -60,9 +60,10 @@ wrap(const relocation_iterator *SI) {
> // ObjectFile creation
> LLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf) {
> std::unique_ptr<MemoryBuffer> Buf(unwrap(MemBuf));
> - ErrorOr<ObjectFile *> ObjOrErr(ObjectFile::createObjectFile(Buf));
> + ErrorOr<std::unique_ptr<ObjectFile>> ObjOrErr(
> + ObjectFile::createObjectFile(Buf));
> Buf.release();
> - ObjectFile *Obj = ObjOrErr ? ObjOrErr.get() : nullptr;
> + ObjectFile *Obj = ObjOrErr ? ObjOrErr.get().release() : nullptr;
> return wrap(Obj);
> }
>
>
> Modified: llvm/trunk/lib/Object/ObjectFile.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/ObjectFile.cpp?rev=214377&r1=214376&r2=214377&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Object/ObjectFile.cpp (original)
> +++ llvm/trunk/lib/Object/ObjectFile.cpp Wed Jul 30 22:12:45 2014
> @@ -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::getRelocate
> return section_iterator(SectionRef(Sec, this));
> }
>
> -ErrorOr<ObjectFile *>
> +ErrorOr<std::unique_ptr<ObjectFile>>
> ObjectFile::createObjectFile(std::unique_ptr<MemoryBuffer> &Object,
> sys::fs::file_magic Type) {
> if (Type == sys::fs::file_magic::unknown)
> @@ -82,7 +84,8 @@ ObjectFile::createObjectFile(std::unique
> llvm_unreachable("Unexpected Object File Type");
> }
>
> -ErrorOr<ObjectFile *> ObjectFile::createObjectFile(StringRef ObjectPath) {
> +ErrorOr<std::unique_ptr<ObjectFile>>
> +ObjectFile::createObjectFile(StringRef ObjectPath) {
> ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
> MemoryBuffer::getFile(ObjectPath);
> if (std::error_code EC = FileOrErr.getError())
>
> Modified: llvm/trunk/lib/Object/SymbolicFile.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/SymbolicFile.cpp?rev=214377&r1=214376&r2=214377&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Object/SymbolicFile.cpp (original)
> +++ llvm/trunk/lib/Object/SymbolicFile.cpp Wed Jul 30 22:12:45 2014
> @@ -25,7 +25,7 @@ SymbolicFile::SymbolicFile(unsigned int
>
> SymbolicFile::~SymbolicFile() {}
>
> -ErrorOr<SymbolicFile *>
> +ErrorOr<std::unique_ptr<SymbolicFile>>
> SymbolicFile::createSymbolicFile(std::unique_ptr<MemoryBuffer> &Object,
> sys::fs::file_magic Type,
> LLVMContext *Context) {
>
> Modified: llvm/trunk/lib/ProfileData/CoverageMappingReader.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/CoverageMappingReader.cpp?rev=214377&r1=214376&r2=214377&view=diff
> ==============================================================================
> --- llvm/trunk/lib/ProfileData/CoverageMappingReader.cpp (original)
> +++ llvm/trunk/lib/ProfileData/CoverageMappingReader.cpp Wed Jul 30 22:12:45 2014
> @@ -282,7 +282,7 @@ ObjectFileCoverageMappingReader::ObjectF
> if (!File)
> error(File.getError());
> else
> - Object.reset(File.get());
> + Object = std::move(File.get());
> }
>
> ObjectFileCoverageMappingReader::ObjectFileCoverageMappingReader(
> @@ -292,7 +292,7 @@ ObjectFileCoverageMappingReader::ObjectF
> if (!File)
> error(File.getError());
> else
> - Object.reset(File.get());
> + Object = std::move(File.get());
> }
>
> namespace {
>
> Modified: llvm/trunk/tools/lli/lli.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lli/lli.cpp?rev=214377&r1=214376&r2=214377&view=diff
> ==============================================================================
> --- llvm/trunk/tools/lli/lli.cpp (original)
> +++ llvm/trunk/tools/lli/lli.cpp Wed Jul 30 22:12:45 2014
> @@ -528,13 +528,13 @@ int main(int argc, char **argv, char * c
> }
>
> for (unsigned i = 0, e = ExtraObjects.size(); i != e; ++i) {
> - ErrorOr<object::ObjectFile *> Obj =
> + ErrorOr<std::unique_ptr<object::ObjectFile>> Obj =
> object::ObjectFile::createObjectFile(ExtraObjects[i]);
> if (!Obj) {
> Err.print(argv[0], errs());
> return 1;
> }
> - EE->addObjectFile(std::unique_ptr<object::ObjectFile>(Obj.get()));
> + EE->addObjectFile(std::move(Obj.get()));
> }
>
> for (unsigned i = 0, e = ExtraArchives.size(); i != e; ++i) {
>
> 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=214377&r1=214376&r2=214377&view=diff
> ==============================================================================
> --- llvm/trunk/tools/llvm-ar/llvm-ar.cpp (original)
> +++ llvm/trunk/tools/llvm-ar/llvm-ar.cpp Wed Jul 30 22:12:45 2014
> @@ -698,12 +698,12 @@ writeSymbolTable(raw_fd_ostream &Out, Ar
> E = Members.end();
> I != E; ++I, ++MemberNum) {
> std::unique_ptr<MemoryBuffer> &MemberBuffer = Buffers[MemberNum];
> - ErrorOr<object::SymbolicFile *> ObjOrErr =
> + ErrorOr<std::unique_ptr<object::SymbolicFile>> 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<object::SymbolicFile> Obj(ObjOrErr.get());
> + std::unique_ptr<object::SymbolicFile> Obj = std::move(ObjOrErr.get());
auto Obj = std::move(ObjOrErr.get()); // or std::move(*ObjOrErr);
Not sure if that's better or not, just a thought. It could just be a
reference to a unique_ptr too, since it's just there to provide a
convenient alias. (or the existing uses of Obj->x could be replaced
with (*Obj)->x). Preivously the separate variable was necessary/nice
when the ObjOrErr wasn't managing ownership already. This recurs in
several places where it might be worth considering dropping the
intermediate variable.
>
> if (!StartOffset) {
> printMemberHeader(Out, "", sys::TimeValue::now(), 0, 0, 0, 0);
>
> Modified: llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp?rev=214377&r1=214376&r2=214377&view=diff
> ==============================================================================
> --- llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp (original)
> +++ llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp Wed Jul 30 22:12:45 2014
> @@ -74,12 +74,13 @@ static void DumpInput(const StringRef &F
> return;
> }
>
> - ErrorOr<ObjectFile *> ObjOrErr(ObjectFile::createObjectFile(Buff.get()));
> + ErrorOr<std::unique_ptr<ObjectFile>> ObjOrErr =
> + ObjectFile::createObjectFile(Buff.get());
> if (std::error_code EC = ObjOrErr.getError()) {
> errs() << Filename << ": " << EC.message() << '\n';
> return;
> }
> - std::unique_ptr<ObjectFile> Obj(ObjOrErr.get());
> + std::unique_ptr<ObjectFile> Obj = std::move(ObjOrErr.get());
>
> std::unique_ptr<DIContext> DICtx(DIContext::getDWARFContext(Obj.get()));
>
>
> Modified: llvm/trunk/tools/llvm-nm/llvm-nm.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-nm/llvm-nm.cpp?rev=214377&r1=214376&r2=214377&view=diff
> ==============================================================================
> --- llvm/trunk/tools/llvm-nm/llvm-nm.cpp (original)
> +++ llvm/trunk/tools/llvm-nm/llvm-nm.cpp Wed Jul 30 22:12:45 2014
> @@ -1009,11 +1009,11 @@ static void dumpSymbolNamesFromFile(std:
> return;
>
> LLVMContext &Context = getGlobalContext();
> - ErrorOr<Binary *> BinaryOrErr =
> + ErrorOr<std::unique_ptr<Binary>> BinaryOrErr =
> createBinary(std::move(*BufferOrErr), &Context);
> if (error(BinaryOrErr.getError(), Filename))
> return;
> - std::unique_ptr<Binary> Bin(BinaryOrErr.get());
> + std::unique_ptr<Binary> Bin = std::move(BinaryOrErr.get());
>
> if (Archive *A = dyn_cast<Archive>(Bin.get())) {
> if (ArchiveMap) {
>
> Modified: llvm/trunk/tools/llvm-objdump/MachODump.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/MachODump.cpp?rev=214377&r1=214376&r2=214377&view=diff
> ==============================================================================
> --- llvm/trunk/tools/llvm-objdump/MachODump.cpp (original)
> +++ llvm/trunk/tools/llvm-objdump/MachODump.cpp Wed Jul 30 22:12:45 2014
> @@ -202,8 +202,8 @@ void llvm::DisassembleInputMachO(StringR
> return;
> }
>
> - std::unique_ptr<MachOObjectFile> MachOOF(static_cast<MachOObjectFile *>(
> - ObjectFile::createMachOObjectFile(Buff.get()).get()));
> + std::unique_ptr<MachOObjectFile> MachOOF =
> + std::move(ObjectFile::createMachOObjectFile(Buff.get()).get());
>
> DisassembleInputMachO2(Filename, MachOOF.get());
> }
> @@ -294,7 +294,7 @@ static void DisassembleInputMachO2(Strin
> errs() << "llvm-objdump: " << Filename << ": " << EC.message() << '\n';
> return;
> }
> - DbgObj = ObjectFile::createMachOObjectFile(Buf.get()).get();
> + DbgObj = ObjectFile::createMachOObjectFile(Buf.get()).get().release();
> }
>
> // Setup the DIContext
>
> Modified: llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp?rev=214377&r1=214376&r2=214377&view=diff
> ==============================================================================
> --- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp (original)
> +++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp Wed Jul 30 22:12:45 2014
> @@ -884,12 +884,12 @@ static void DumpInput(StringRef file) {
> }
>
> // Attempt to open the binary.
> - ErrorOr<Binary *> BinaryOrErr = createBinary(file);
> + ErrorOr<std::unique_ptr<Binary>> BinaryOrErr = createBinary(file);
> if (std::error_code EC = BinaryOrErr.getError()) {
> errs() << ToolName << ": '" << file << "': " << EC.message() << ".\n";
> return;
> }
> - std::unique_ptr<Binary> binary(BinaryOrErr.get());
> + std::unique_ptr<Binary> binary = std::move(BinaryOrErr.get());
>
> if (Archive *a = dyn_cast<Archive>(binary.get()))
> DumpArchive(a);
>
> Modified: llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp?rev=214377&r1=214376&r2=214377&view=diff
> ==============================================================================
> --- llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp (original)
> +++ llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp Wed Jul 30 22:12:45 2014
> @@ -287,12 +287,12 @@ static void dumpInput(StringRef File) {
> }
>
> // Attempt to open the binary.
> - ErrorOr<Binary *> BinaryOrErr = createBinary(File);
> + ErrorOr<std::unique_ptr<Binary>> BinaryOrErr = createBinary(File);
> if (std::error_code EC = BinaryOrErr.getError()) {
> reportError(File, EC);
> return;
> }
> - std::unique_ptr<Binary> Binary(BinaryOrErr.get());
> + std::unique_ptr<Binary> Binary = std::move(BinaryOrErr.get());
>
> if (Archive *Arc = dyn_cast<Archive>(Binary.get()))
> dumpArchive(Arc);
>
> Modified: llvm/trunk/tools/llvm-size/llvm-size.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-size/llvm-size.cpp?rev=214377&r1=214376&r2=214377&view=diff
> ==============================================================================
> --- llvm/trunk/tools/llvm-size/llvm-size.cpp (original)
> +++ llvm/trunk/tools/llvm-size/llvm-size.cpp Wed Jul 30 22:12:45 2014
> @@ -453,12 +453,12 @@ static void PrintFileSectionSizes(String
> }
>
> // Attempt to open the binary.
> - ErrorOr<Binary *> BinaryOrErr = createBinary(file);
> + ErrorOr<std::unique_ptr<Binary>> BinaryOrErr = createBinary(file);
> if (std::error_code EC = BinaryOrErr.getError()) {
> errs() << ToolName << ": " << file << ": " << EC.message() << ".\n";
> return;
> }
> - std::unique_ptr<Binary> binary(BinaryOrErr.get());
> + std::unique_ptr<Binary> binary = std::move(BinaryOrErr.get());
>
> if (Archive *a = dyn_cast<Archive>(binary.get())) {
> // This is an archive. Iterate over each member and display its sizes.
>
> Modified: llvm/trunk/tools/llvm-symbolizer/LLVMSymbolize.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-symbolizer/LLVMSymbolize.cpp?rev=214377&r1=214376&r2=214377&view=diff
> ==============================================================================
> --- llvm/trunk/tools/llvm-symbolizer/LLVMSymbolize.cpp (original)
> +++ llvm/trunk/tools/llvm-symbolizer/LLVMSymbolize.cpp Wed Jul 30 22:12:45 2014
> @@ -300,9 +300,9 @@ LLVMSymbolizer::getOrCreateBinary(const
> return I->second;
> Binary *Bin = nullptr;
> Binary *DbgBin = nullptr;
> - ErrorOr<Binary *> BinaryOrErr = createBinary(Path);
> + ErrorOr<std::unique_ptr<Binary>> BinaryOrErr = createBinary(Path);
> if (!error(BinaryOrErr.getError())) {
Drive by: this seems overly verbose (equivalent to "if (BinaryOrErr)"
and could have the variable declaration/initialization rolled into it
as well)
> - std::unique_ptr<Binary> ParsedBinary(BinaryOrErr.get());
> + std::unique_ptr<Binary> 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
> 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<Binary>(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
> findDebugBinary(Path, DebuglinkName, CRCHash, DebugBinaryPath)) {
> BinaryOrErr = createBinary(DebugBinaryPath);
> if (!error(BinaryOrErr.getError())) {
> - DbgBin = BinaryOrErr.get();
> - ParsedBinariesAndObjects.push_back(std::unique_ptr<Binary>(DbgBin));
> + DbgBin = BinaryOrErr.get().get();
> + ParsedBinariesAndObjects.push_back(std::move(BinaryOrErr.get()));
> }
> }
> }
>
> Modified: llvm/trunk/tools/llvm-vtabledump/llvm-vtabledump.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-vtabledump/llvm-vtabledump.cpp?rev=214377&r1=214376&r2=214377&view=diff
> ==============================================================================
> --- llvm/trunk/tools/llvm-vtabledump/llvm-vtabledump.cpp (original)
> +++ llvm/trunk/tools/llvm-vtabledump/llvm-vtabledump.cpp Wed Jul 30 22:12:45 2014
> @@ -164,12 +164,12 @@ static void dumpInput(StringRef File) {
> }
>
> // Attempt to open the binary.
> - ErrorOr<Binary *> BinaryOrErr = createBinary(File);
> + ErrorOr<std::unique_ptr<Binary>> BinaryOrErr = createBinary(File);
> if (std::error_code EC = BinaryOrErr.getError()) {
> reportError(File, EC);
> return;
> }
> - std::unique_ptr<Binary> Binary(BinaryOrErr.get());
> + std::unique_ptr<Binary> Binary = std::move(BinaryOrErr.get());
>
> if (Archive *Arc = dyn_cast<Archive>(Binary.get()))
> dumpArchive(Arc);
>
> Modified: llvm/trunk/tools/macho-dump/macho-dump.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/macho-dump/macho-dump.cpp?rev=214377&r1=214376&r2=214377&view=diff
> ==============================================================================
> --- llvm/trunk/tools/macho-dump/macho-dump.cpp (original)
> +++ llvm/trunk/tools/macho-dump/macho-dump.cpp Wed Jul 30 22:12:45 2014
> @@ -403,10 +403,10 @@ int main(int argc, char **argv) {
>
> cl::ParseCommandLineOptions(argc, argv, "llvm Mach-O dumping tool\n");
>
> - ErrorOr<Binary *> BinaryOrErr = createBinary(InputFile);
> + 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(BinaryOrErr.get());
> + std::unique_ptr<Binary> Binary = std::move((BinaryOrErr.get()));
>
> const MachOObjectFile *InputObject = dyn_cast<MachOObjectFile>(Binary.get());
> if (!InputObject)
>
> Modified: llvm/trunk/tools/obj2yaml/obj2yaml.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/obj2yaml/obj2yaml.cpp?rev=214377&r1=214376&r2=214377&view=diff
> ==============================================================================
> --- llvm/trunk/tools/obj2yaml/obj2yaml.cpp (original)
> +++ llvm/trunk/tools/obj2yaml/obj2yaml.cpp Wed Jul 30 22:12:45 2014
> @@ -32,11 +32,11 @@ static std::error_code dumpInput(StringR
> if (File != "-" && !sys::fs::exists(File))
> return obj2yaml_error::file_not_found;
>
> - ErrorOr<Binary *> BinaryOrErr = createBinary(File);
> + ErrorOr<std::unique_ptr<Binary>> BinaryOrErr = createBinary(File);
> if (std::error_code EC = BinaryOrErr.getError())
> return EC;
>
> - std::unique_ptr<Binary> Binary(BinaryOrErr.get());
> + std::unique_ptr<Binary> Binary = std::move(BinaryOrErr.get());
> // TODO: If this is an archive, then burst it and dump each entry
> if (ObjectFile *Obj = dyn_cast<ObjectFile>(Binary.get()))
> return dumpObject(*Obj);
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list