[PATCH] D65951: [llvm-readobj] - Remove unwrapOrError(ErrorOr<T> EO) helper.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 8 06:57:35 PDT 2019
grimar created this revision.
grimar added reviewers: jhenderson, MaskRay.
Herald added a subscriber: rupprecht.
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.
https://reviews.llvm.org/D65951
Files:
tools/llvm-readobj/COFFDumper.cpp
tools/llvm-readobj/llvm-readobj.h
Index: tools/llvm-readobj/llvm-readobj.h
===================================================================
--- tools/llvm-readobj/llvm-readobj.h
+++ tools/llvm-readobj/llvm-readobj.h
@@ -33,12 +33,6 @@
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)
Index: tools/llvm-readobj/COFFDumper.cpp
===================================================================
--- tools/llvm-readobj/COFFDumper.cpp
+++ 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<StringError>(Err, object_error::parse_failed);
+}
+
namespace {
struct LoadConfigTables {
@@ -167,7 +171,7 @@
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 @@
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<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];
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65951.214144.patch
Type: text/x-patch
Size: 2780 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190808/ceee427e/attachment.bin>
More information about the llvm-commits
mailing list