From ff9f5f33726a31dcb254d0d4c36506de592127dc Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 10 Oct 2017 19:14:30 +0000 Subject: [PATCH] Return Expected from createRTDyldELFObject. No functionality change, it just makes it easier to use Expected in Object. llvm-svn: 315348 --- .../RuntimeDyld/RuntimeDyldELF.cpp | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp index bf527f5ca827..57289a125e1e 100644 --- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp +++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp @@ -133,14 +133,17 @@ public: }; template -static std::unique_ptr> +static Expected>> createRTDyldELFObject(MemoryBufferRef Buffer, const ObjectFile &SourceObject, - const LoadedELFObjectInfo &L, std::error_code &ec) { + const LoadedELFObjectInfo &L) { typedef typename ELFFile::Elf_Shdr Elf_Shdr; typedef typename ELFDataTypeTypedefHelper::value_type addr_type; + std::error_code EC; std::unique_ptr> Obj = - llvm::make_unique>(Buffer, ec); + llvm::make_unique>(Buffer, EC); + if (EC) + return errorCodeToError(EC); // Iterate over all sections in the object. auto SI = SourceObject.section_begin(); @@ -171,27 +174,25 @@ createELFDebugObject(const ObjectFile &Obj, const LoadedELFObjectInfo &L) { std::unique_ptr Buffer = MemoryBuffer::getMemBufferCopy(Obj.getData(), Obj.getFileName()); - std::error_code ec; - - std::unique_ptr DebugObj; + Expected> DebugObj(nullptr); + handleAllErrors(DebugObj.takeError()); if (Obj.getBytesInAddress() == 4 && Obj.isLittleEndian()) - DebugObj = createRTDyldELFObject(Buffer->getMemBufferRef(), Obj, L, - ec); + DebugObj = + createRTDyldELFObject(Buffer->getMemBufferRef(), Obj, L); else if (Obj.getBytesInAddress() == 4 && !Obj.isLittleEndian()) - DebugObj = createRTDyldELFObject(Buffer->getMemBufferRef(), Obj, L, - ec); + DebugObj = + createRTDyldELFObject(Buffer->getMemBufferRef(), Obj, L); else if (Obj.getBytesInAddress() == 8 && !Obj.isLittleEndian()) - DebugObj = createRTDyldELFObject(Buffer->getMemBufferRef(), Obj, L, - ec); + DebugObj = + createRTDyldELFObject(Buffer->getMemBufferRef(), Obj, L); else if (Obj.getBytesInAddress() == 8 && Obj.isLittleEndian()) - DebugObj = createRTDyldELFObject(Buffer->getMemBufferRef(), Obj, L, - ec); + DebugObj = + createRTDyldELFObject(Buffer->getMemBufferRef(), Obj, L); else llvm_unreachable("Unexpected ELF format"); - assert(!ec && "Could not construct copy ELF object file"); - - return OwningBinary(std::move(DebugObj), std::move(Buffer)); + handleAllErrors(DebugObj.takeError()); + return OwningBinary(std::move(*DebugObj), std::move(Buffer)); } OwningBinary