diff --git a/include/llvm/Object/Binary.h b/include/llvm/Object/Binary.h index 9be2fbe0837..91984cb5271 100644 --- a/include/llvm/Object/Binary.h +++ b/include/llvm/Object/Binary.h @@ -125,10 +125,8 @@ public: /// @brief Create a Binary from Source, autodetecting the file type. /// -/// @param Source The data to create the Binary from. Ownership is transferred -/// to the Binary if successful. If an error is returned, -/// Source is destroyed by createBinary before returning. -ErrorOr createBinary(std::unique_ptr &Source, +/// @param Source The data to create the Binary from. +ErrorOr createBinary(std::unique_ptr Source, LLVMContext *Context = nullptr); ErrorOr createBinary(StringRef Path); diff --git a/lib/Object/Archive.cpp b/lib/Object/Archive.cpp index 3c683408969..e32bdd5c5be 100644 --- a/lib/Object/Archive.cpp +++ b/lib/Object/Archive.cpp @@ -181,7 +181,7 @@ Archive::Child::getAsBinary(LLVMContext *Context) const { if (std::error_code EC = BuffOrErr.getError()) return EC; - return createBinary(*BuffOrErr, Context); + return createBinary(std::move(*BuffOrErr), Context); } ErrorOr Archive::create(std::unique_ptr Source) { diff --git a/lib/Object/Binary.cpp b/lib/Object/Binary.cpp index 9f6a68556f9..552d5db89c5 100644 --- a/lib/Object/Binary.cpp +++ b/lib/Object/Binary.cpp @@ -38,7 +38,7 @@ StringRef Binary::getFileName() const { return Data->getBufferIdentifier(); } -ErrorOr object::createBinary(std::unique_ptr &Buffer, +ErrorOr object::createBinary(std::unique_ptr Buffer, LLVMContext *Context) { sys::fs::file_magic Type = sys::fs::identify_magic(Buffer->getBuffer()); @@ -79,5 +79,5 @@ ErrorOr object::createBinary(StringRef Path) { MemoryBuffer::getFileOrSTDIN(Path); if (std::error_code EC = FileOrErr.getError()) return EC; - return createBinary(FileOrErr.get()); + return createBinary(std::move(*FileOrErr)); } diff --git a/tools/llvm-nm/llvm-nm.cpp b/tools/llvm-nm/llvm-nm.cpp index d021a0d341f..15304c40b88 100644 --- a/tools/llvm-nm/llvm-nm.cpp +++ b/tools/llvm-nm/llvm-nm.cpp @@ -993,13 +993,12 @@ static void dumpSymbolNamesFromFile(std::string &Filename) { MemoryBuffer::getFileOrSTDIN(Filename); if (error(BufferOrErr.getError(), Filename)) return; - std::unique_ptr Buffer = std::move(BufferOrErr.get()); LLVMContext &Context = getGlobalContext(); - ErrorOr BinaryOrErr = createBinary(Buffer, &Context); + ErrorOr BinaryOrErr = + createBinary(std::move(*BufferOrErr), &Context); if (error(BinaryOrErr.getError(), Filename)) return; - Buffer.release(); std::unique_ptr Bin(BinaryOrErr.get()); if (Archive *A = dyn_cast(Bin.get())) {