Index: llvm/trunk/tools/llvm-readobj/COFFDumper.cpp =================================================================== --- llvm/trunk/tools/llvm-readobj/COFFDumper.cpp +++ llvm/trunk/tools/llvm-readobj/COFFDumper.cpp @@ -60,6 +60,10 @@ using namespace llvm::support; using namespace llvm::Win64EH; +static inline Error createError(const Twine &Err) { + return make_error(Err, object_error::parse_failed); +} + namespace { struct LoadConfigTables { @@ -167,7 +171,7 @@ void printDelayImportedSymbols( const DelayImportDirectoryEntryRef &I, iterator_range Range); - ErrorOr + Expected getResourceDirectoryTableEntry(const coff_resource_dir_table &Table, uint32_t Index); @@ -1729,7 +1733,8 @@ uint32_t TotalEntries = 0; for (int i = 0; i < Table.NumberOfNameEntries + Table.NumberOfIDEntries; i++) { - auto Entry = unwrapOrError(getResourceDirectoryTableEntry(Table, i)); + auto Entry = unwrapOrError(Obj->getFileName(), + getResourceDirectoryTableEntry(Table, i)); if (Entry.Offset.isSubDir()) { StringRef NextLevel; if (Level == "Name") @@ -1755,7 +1760,8 @@ // Iterate through level in resource directory tree. for (int i = 0; i < Table.NumberOfNameEntries + Table.NumberOfIDEntries; i++) { - auto Entry = unwrapOrError(getResourceDirectoryTableEntry(Table, i)); + auto Entry = unwrapOrError(Obj->getFileName(), + getResourceDirectoryTableEntry(Table, i)); StringRef Name; SmallString<20> IDStr; raw_svector_ostream OS(IDStr); @@ -1808,11 +1814,11 @@ } } -ErrorOr +Expected COFFDumper::getResourceDirectoryTableEntry(const coff_resource_dir_table &Table, uint32_t Index) { if (Index >= (uint32_t)(Table.NumberOfNameEntries + Table.NumberOfIDEntries)) - return object_error::parse_failed; + return createError("can't get resource directory table entry"); auto TablePtr = reinterpret_cast(&Table + 1); return TablePtr[Index]; } Index: llvm/trunk/tools/llvm-readobj/llvm-readobj.h =================================================================== --- llvm/trunk/tools/llvm-readobj/llvm-readobj.h +++ llvm/trunk/tools/llvm-readobj/llvm-readobj.h @@ -33,12 +33,6 @@ return std::move(*E); } - template T unwrapOrError(ErrorOr EO) { - if (EO) - return *EO; - reportError(EO.getError().message()); - } - // TODO: This one is deprecated. Use one with a Input name below. template T unwrapOrError(Expected EO) { if (EO)