Convert two uses of ErrorOr to Expected.

llvm-svn: 315354
This commit is contained in:
Rafael Espindola 2017-10-10 20:00:07 +00:00
parent de4b88d9a1
commit 12db383e20
5 changed files with 13 additions and 14 deletions

View File

@ -23,7 +23,6 @@
#include "llvm/Object/SymbolicFile.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBuffer.h"
#include <cassert>
@ -322,10 +321,10 @@ public:
return v->isObject();
}
static ErrorOr<std::unique_ptr<COFFObjectFile>>
static Expected<std::unique_ptr<COFFObjectFile>>
createCOFFObjectFile(MemoryBufferRef Object);
static ErrorOr<std::unique_ptr<ObjectFile>>
static Expected<std::unique_ptr<ObjectFile>>
createELFObjectFile(MemoryBufferRef Object);
static Expected<std::unique_ptr<MachOObjectFile>>

View File

@ -1590,12 +1590,12 @@ std::error_code ImportedSymbolRef::getOrdinal(uint16_t &Result) const {
return std::error_code();
}
ErrorOr<std::unique_ptr<COFFObjectFile>>
Expected<std::unique_ptr<COFFObjectFile>>
ObjectFile::createCOFFObjectFile(MemoryBufferRef Object) {
std::error_code EC;
std::unique_ptr<COFFObjectFile> Ret(new COFFObjectFile(Object, EC));
if (EC)
return EC;
return errorCodeToError(EC);
return std::move(Ret);
}

View File

@ -37,7 +37,7 @@ using namespace object;
ELFObjectFileBase::ELFObjectFileBase(unsigned int Type, MemoryBufferRef Source)
: ObjectFile(Type, Source) {}
ErrorOr<std::unique_ptr<ObjectFile>>
Expected<std::unique_ptr<ObjectFile>>
ObjectFile::createELFObjectFile(MemoryBufferRef Obj) {
std::pair<unsigned char, unsigned char> Ident =
getElfArchType(Obj.getBuffer());
@ -45,7 +45,7 @@ ObjectFile::createELFObjectFile(MemoryBufferRef Obj) {
1ULL << countTrailingZeros(uintptr_t(Obj.getBufferStart()));
if (MaxAlignment < 2)
return object_error::parse_failed;
return createError("Insufficient alignment");
std::error_code EC;
std::unique_ptr<ObjectFile> R;
@ -55,20 +55,20 @@ ObjectFile::createELFObjectFile(MemoryBufferRef Obj) {
else if (Ident.second == ELF::ELFDATA2MSB)
R.reset(new ELFObjectFile<ELFType<support::big, false>>(Obj, EC));
else
return object_error::parse_failed;
return createError("Invalid ELF data");
} else if (Ident.first == ELF::ELFCLASS64) {
if (Ident.second == ELF::ELFDATA2LSB)
R.reset(new ELFObjectFile<ELFType<support::little, true>>(Obj, EC));
else if (Ident.second == ELF::ELFDATA2MSB)
R.reset(new ELFObjectFile<ELFType<support::big, true>>(Obj, EC));
else
return object_error::parse_failed;
return createError("Invalid ELF data");
} else {
return object_error::parse_failed;
return createError("Invalid ELF class");
}
if (EC)
return EC;
return errorCodeToError(EC);
return std::move(R);
}

View File

@ -125,7 +125,7 @@ ObjectFile::createObjectFile(MemoryBufferRef Object, file_magic Type) {
case file_magic::elf_executable:
case file_magic::elf_shared_object:
case file_magic::elf_core:
return errorOrToExpected(createELFObjectFile(Object));
return createELFObjectFile(Object);
case file_magic::macho_object:
case file_magic::macho_executable:
case file_magic::macho_fixed_virtual_memory_shared_lib:
@ -141,7 +141,7 @@ ObjectFile::createObjectFile(MemoryBufferRef Object, file_magic Type) {
case file_magic::coff_object:
case file_magic::coff_import_library:
case file_magic::pecoff_executable:
return errorOrToExpected(createCOFFObjectFile(Object));
return createCOFFObjectFile(Object);
case file_magic::wasm_object:
return createWasmObjectFile(Object);
}

View File

@ -58,7 +58,7 @@ GNU AR is able to parse the unaligned member and warns about the member with
the unknown format. We should probably simply warn on both. For now we just
produce an error for the unknown format.
RUN: not llvm-nm %p/Inputs/corrupt-archive.a 2>&1 | FileCheck %s -check-prefix CORRUPT
CORRUPT: corrupt-archive.a(trivial-object-test2.elf-x86-64) Invalid data was encountered while parsing the file
CORRUPT: corrupt-archive.a(trivial-object-test2.elf-x86-64) Insufficient alignment
RUN: llvm-nm %p/Inputs/thin.a | FileCheck %s -check-prefix THIN