[llvm] r368410 - [llvm-readobj] - Remove unwrapOrError(ErrorOr<T> EO) helper.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 9 01:29:26 PDT 2019
Author: grimar
Date: Fri Aug 9 01:29:26 2019
New Revision: 368410
URL: http://llvm.org/viewvc/llvm-project?rev=368410&view=rev
Log:
[llvm-readobj] - Remove unwrapOrError(ErrorOr<T> EO) helper.
It is outdated. Using of Expected<> is preferred, also it does
not provide a way to report a file name.
I updated the code to use the modern version of unwrapOrError instead.
Differential revision: https://reviews.llvm.org/D65951
Modified:
llvm/trunk/tools/llvm-readobj/COFFDumper.cpp
llvm/trunk/tools/llvm-readobj/llvm-readobj.h
Modified: llvm/trunk/tools/llvm-readobj/COFFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/COFFDumper.cpp?rev=368410&r1=368409&r2=368410&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/COFFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/COFFDumper.cpp Fri Aug 9 01:29:26 2019
@@ -60,6 +60,10 @@ using namespace llvm::codeview;
using namespace llvm::support;
using namespace llvm::Win64EH;
+static inline Error createError(const Twine &Err) {
+ return make_error<StringError>(Err, object_error::parse_failed);
+}
+
namespace {
struct LoadConfigTables {
@@ -167,7 +171,7 @@ private:
void printDelayImportedSymbols(
const DelayImportDirectoryEntryRef &I,
iterator_range<imported_symbol_iterator> Range);
- ErrorOr<const coff_resource_dir_entry &>
+ Expected<const coff_resource_dir_entry &>
getResourceDirectoryTableEntry(const coff_resource_dir_table &Table,
uint32_t Index);
@@ -1729,7 +1733,8 @@ COFFDumper::countTotalTableEntries(Resou
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 @@ void COFFDumper::printResourceDirectoryT
// 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 @@ void COFFDumper::printResourceDirectoryT
}
}
-ErrorOr<const coff_resource_dir_entry &>
+Expected<const coff_resource_dir_entry &>
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<const coff_resource_dir_entry *>(&Table + 1);
return TablePtr[Index];
}
Modified: llvm/trunk/tools/llvm-readobj/llvm-readobj.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/llvm-readobj.h?rev=368410&r1=368409&r2=368410&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/llvm-readobj.h (original)
+++ llvm/trunk/tools/llvm-readobj/llvm-readobj.h Fri Aug 9 01:29:26 2019
@@ -33,12 +33,6 @@ namespace llvm {
return std::move(*E);
}
- template <class T> T unwrapOrError(ErrorOr<T> EO) {
- if (EO)
- return *EO;
- reportError(EO.getError().message());
- }
-
// TODO: This one is deprecated. Use one with a Input name below.
template <class T> T unwrapOrError(Expected<T> EO) {
if (EO)
More information about the llvm-commits
mailing list