Skip to content

Commit ae610ab

Browse files
committed
[Object] Revert r275316, Archive::child_iterator changes, while I update lld.
Should fix the bots broken by r275316. llvm-svn: 275353
1 parent 7f781ab commit ae610ab

File tree

15 files changed

+197
-236
lines changed

15 files changed

+197
-236
lines changed

llvm/include/llvm/Object/Archive.h

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,21 @@ class Archive : public Binary {
106106
};
107107

108108
class child_iterator {
109-
Child C;
110-
Error *E;
109+
ErrorOr<Child> child;
111110

112111
public:
113-
child_iterator() : C(Child(nullptr, nullptr, nullptr)), E(nullptr) {}
114-
child_iterator(const Child &C, Error *E) : C(C), E(E) {}
115-
const Child *operator->() const { return &C; }
116-
const Child &operator*() const { return C; }
112+
child_iterator() : child(Child(nullptr, nullptr, nullptr)) {}
113+
child_iterator(const Child &c) : child(c) {}
114+
child_iterator(std::error_code EC) : child(EC) {}
115+
const ErrorOr<Child> *operator->() const { return &child; }
116+
const ErrorOr<Child> &operator*() const { return child; }
117117

118118
bool operator==(const child_iterator &other) const {
119-
// Ignore errors here: If an error occurred during increment then getNext
120-
// will have been set to child_end(), and the following comparison should
121-
// do the right thing.
122-
return C == other.C;
119+
// We ignore error states so that comparisions with end() work, which
120+
// allows range loops.
121+
if (child.getError() || other.child.getError())
122+
return false;
123+
return *child == *other.child;
123124
}
124125

125126
bool operator!=(const child_iterator &other) const {
@@ -129,15 +130,8 @@ class Archive : public Binary {
129130
// Code in loops with child_iterators must check for errors on each loop
130131
// iteration. And if there is an error break out of the loop.
131132
child_iterator &operator++() { // Preincrement
132-
assert(E && "Can't increment iterator with no Error attached");
133-
if (auto ChildOrErr = C.getNext())
134-
C = *ChildOrErr;
135-
else {
136-
ErrorAsOutParameter ErrAsOutParam(*E);
137-
C = C.getParent()->child_end().C;
138-
*E = errorCodeToError(ChildOrErr.getError());
139-
E = nullptr;
140-
}
133+
assert(child && "Can't increment iterator with error");
134+
child = child->getNext();
141135
return *this;
142136
}
143137
};
@@ -196,11 +190,10 @@ class Archive : public Binary {
196190
Kind kind() const { return (Kind)Format; }
197191
bool isThin() const { return IsThin; }
198192

199-
child_iterator child_begin(Error &Err, bool SkipInternal = true) const;
193+
child_iterator child_begin(bool SkipInternal = true) const;
200194
child_iterator child_end() const;
201-
iterator_range<child_iterator> children(Error &Err,
202-
bool SkipInternal = true) const {
203-
return make_range(child_begin(Err, SkipInternal), child_end());
195+
iterator_range<child_iterator> children(bool SkipInternal = true) const {
196+
return make_range(child_begin(SkipInternal), child_end());
204197
}
205198

206199
symbol_iterator symbol_begin() const;
@@ -215,7 +208,7 @@ class Archive : public Binary {
215208
}
216209

217210
// check if a symbol is in the archive
218-
child_iterator findSym(Error &Err, StringRef name) const;
211+
child_iterator findSym(StringRef name) const;
219212

220213
bool hasSymbolTable() const;
221214
StringRef getSymbolTable() const { return SymbolTable; }

llvm/include/llvm/Support/Error.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -940,11 +940,6 @@ class ExitOnError {
940940
std::function<int(const Error &)> GetExitCode;
941941
};
942942

943-
/// Report a serious error, calling any installed error handler. See
944-
/// ErrorHandling.h.
945-
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err,
946-
bool gen_crash_diag = true);
947-
948943
} // namespace llvm
949944

950945
#endif // LLVM_SUPPORT_ERROR_H

llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,14 +327,13 @@ RuntimeDyld::SymbolInfo MCJIT::findSymbol(const std::string &Name,
327327
for (object::OwningBinary<object::Archive> &OB : Archives) {
328328
object::Archive *A = OB.getBinary();
329329
// Look for our symbols in each Archive
330-
Error Err;
331-
object::Archive::child_iterator ChildIt = A->findSym(Err, Name);
332-
if (Err)
333-
report_fatal_error(std::move(Err));
330+
object::Archive::child_iterator ChildIt = A->findSym(Name);
331+
if (std::error_code EC = ChildIt->getError())
332+
report_fatal_error(EC.message());
334333
if (ChildIt != A->child_end()) {
335334
// FIXME: Support nested archives?
336335
Expected<std::unique_ptr<object::Binary>> ChildBinOrErr =
337-
ChildIt->getAsBinary();
336+
(*ChildIt)->getAsBinary();
338337
if (!ChildBinOrErr) {
339338
// TODO: Actually report errors helpfully.
340339
consumeError(ChildBinOrErr.takeError());

llvm/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,13 @@ class OrcMCJITReplacement : public ExecutionEngine {
258258
for (object::OwningBinary<object::Archive> &OB : Archives) {
259259
object::Archive *A = OB.getBinary();
260260
// Look for our symbols in each Archive
261-
Error Err;
262-
object::Archive::child_iterator ChildIt = A->findSym(Err, Name);
263-
if (Err)
264-
report_fatal_error(std::move(Err));
261+
object::Archive::child_iterator ChildIt = A->findSym(Name);
262+
if (std::error_code EC = ChildIt->getError())
263+
report_fatal_error(EC.message());
265264
if (ChildIt != A->child_end()) {
266265
// FIXME: Support nested archives?
267266
Expected<std::unique_ptr<object::Binary>> ChildBinOrErr =
268-
ChildIt->getAsBinary();
267+
(*ChildIt)->getAsBinary();
269268
if (!ChildBinOrErr) {
270269
// TODO: Actually report errors helpfully.
271270
consumeError(ChildBinOrErr.takeError());

llvm/lib/Object/Archive.cpp

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,12 @@ Archive::Archive(MemoryBufferRef Source, Error &Err)
298298
}
299299

300300
// Get the special members.
301-
child_iterator I = child_begin(Err, false);
302-
if (Err)
301+
child_iterator I = child_begin(false);
302+
std::error_code ec;
303+
if ((ec = I->getError())) {
304+
Err = errorCodeToError(ec);
303305
return;
306+
}
304307
child_iterator E = child_end();
305308

306309
// This is at least a valid empty archive. Since an empty archive is the
@@ -312,13 +315,13 @@ Archive::Archive(MemoryBufferRef Source, Error &Err)
312315
Err = Error::success();
313316
return;
314317
}
315-
const Child *C = &*I;
318+
const Child *C = &**I;
316319

317320
auto Increment = [&]() {
318321
++I;
319-
if (Err)
322+
if ((Err = errorCodeToError(I->getError())))
320323
return true;
321-
C = &*I;
324+
C = &**I;
322325
return false;
323326
};
324327

@@ -363,7 +366,8 @@ Archive::Archive(MemoryBufferRef Source, Error &Err)
363366
Format = K_BSD;
364367
// We know this is BSD, so getName will work since there is no string table.
365368
ErrorOr<StringRef> NameOrErr = C->getName();
366-
if (auto ec = NameOrErr.getError()) {
369+
ec = NameOrErr.getError();
370+
if (ec) {
367371
Err = errorCodeToError(ec);
368372
return;
369373
}
@@ -461,29 +465,23 @@ Archive::Archive(MemoryBufferRef Source, Error &Err)
461465
Err = Error::success();
462466
}
463467

464-
Archive::child_iterator Archive::child_begin(Error &Err,
465-
bool SkipInternal) const {
468+
Archive::child_iterator Archive::child_begin(bool SkipInternal) const {
466469
if (Data.getBufferSize() == 8) // empty archive.
467470
return child_end();
468471

469472
if (SkipInternal)
470-
return child_iterator(Child(this, FirstRegularData,
471-
FirstRegularStartOfFile),
472-
&Err);
473+
return Child(this, FirstRegularData, FirstRegularStartOfFile);
473474

474475
const char *Loc = Data.getBufferStart() + strlen(Magic);
475476
std::error_code EC;
476-
Child C(this, Loc, &EC);
477-
if (EC) {
478-
ErrorAsOutParameter ErrAsOutParam(Err);
479-
Err = errorCodeToError(EC);
480-
return child_end();
481-
}
482-
return child_iterator(C, &Err);
477+
Child c(this, Loc, &EC);
478+
if (EC)
479+
return child_iterator(EC);
480+
return child_iterator(c);
483481
}
484482

485483
Archive::child_iterator Archive::child_end() const {
486-
return child_iterator(Child(this, nullptr, nullptr), nullptr);
484+
return Child(this, nullptr, nullptr);
487485
}
488486

489487
StringRef Archive::Symbol::getName() const {
@@ -667,20 +665,18 @@ uint32_t Archive::getNumberOfSymbols() const {
667665
return read32le(buf);
668666
}
669667

670-
Archive::child_iterator Archive::findSym(Error &Err, StringRef name) const {
668+
Archive::child_iterator Archive::findSym(StringRef name) const {
671669
Archive::symbol_iterator bs = symbol_begin();
672670
Archive::symbol_iterator es = symbol_end();
673671

674672
for (; bs != es; ++bs) {
675673
StringRef SymName = bs->getName();
676674
if (SymName == name) {
677-
if (auto MemberOrErr = bs->getMember()) {
678-
return child_iterator(*MemberOrErr, &Err);
679-
} else {
680-
ErrorAsOutParameter ErrAsOutParam(Err);
681-
Err = errorCodeToError(MemberOrErr.getError());
675+
ErrorOr<Archive::child_iterator> ResultOrErr = bs->getMember();
676+
// FIXME: Should we really eat the error?
677+
if (ResultOrErr.getError())
682678
return child_end();
683-
}
679+
return ResultOrErr.get();
684680
}
685681
}
686682
return child_end();

llvm/lib/Support/Error.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner) {
6464
});
6565
}
6666

67-
6867
std::error_code ErrorList::convertToErrorCode() const {
6968
return std::error_code(static_cast<int>(ErrorErrorCode::MultipleErrors),
7069
*ErrorErrorCat);
@@ -100,14 +99,4 @@ std::error_code StringError::convertToErrorCode() const {
10099
return EC;
101100
}
102101

103-
void report_fatal_error(Error Err, bool GenCrashDiag) {
104-
assert(Err && "report_fatal_error called with success value");
105-
std::string ErrMsg;
106-
{
107-
raw_string_ostream ErrStream(ErrMsg);
108-
logAllUnhandledErrors(std::move(Err), ErrStream, "");
109-
}
110-
report_fatal_error(ErrMsg);
111-
}
112-
113102
}

llvm/tools/dsymutil/BinaryHolder.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,10 @@ BinaryHolder::GetArchiveMemberBuffers(StringRef Filename,
102102
Buffers.reserve(CurrentArchives.size());
103103

104104
for (const auto &CurrentArchive : CurrentArchives) {
105-
Error Err;
106-
for (auto Child : CurrentArchive->children(Err)) {
105+
for (auto ChildOrErr : CurrentArchive->children()) {
106+
if (std::error_code Err = ChildOrErr.getError())
107+
return Err;
108+
const auto &Child = *ChildOrErr;
107109
if (auto NameOrErr = Child.getName()) {
108110
if (*NameOrErr == Filename) {
109111
if (Timestamp != sys::TimeValue::PosixZeroTime() &&
@@ -121,8 +123,6 @@ BinaryHolder::GetArchiveMemberBuffers(StringRef Filename,
121123
}
122124
}
123125
}
124-
if (Err)
125-
return errorToErrorCode(std::move(Err));
126126
}
127127

128128
if (Buffers.empty())

llvm/tools/llvm-ar/llvm-ar.cpp

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -405,37 +405,35 @@ static void performReadOperation(ArchiveOperation Operation,
405405
fail("extracting from a thin archive is not supported");
406406

407407
bool Filter = !Members.empty();
408-
{
409-
Error Err;
410-
for (auto &C : OldArchive->children(Err)) {
411-
ErrorOr<StringRef> NameOrErr = C.getName();
412-
failIfError(NameOrErr.getError());
413-
StringRef Name = NameOrErr.get();
414-
415-
if (Filter) {
416-
auto I = std::find(Members.begin(), Members.end(), Name);
417-
if (I == Members.end())
418-
continue;
419-
Members.erase(I);
420-
}
408+
for (auto &ChildOrErr : OldArchive->children()) {
409+
failIfError(ChildOrErr.getError());
410+
const object::Archive::Child &C = *ChildOrErr;
411+
412+
ErrorOr<StringRef> NameOrErr = C.getName();
413+
failIfError(NameOrErr.getError());
414+
StringRef Name = NameOrErr.get();
415+
416+
if (Filter) {
417+
auto I = std::find(Members.begin(), Members.end(), Name);
418+
if (I == Members.end())
419+
continue;
420+
Members.erase(I);
421+
}
421422

422-
switch (Operation) {
423-
default:
424-
llvm_unreachable("Not a read operation");
425-
case Print:
426-
doPrint(Name, C);
427-
break;
428-
case DisplayTable:
429-
doDisplayTable(Name, C);
430-
break;
431-
case Extract:
432-
doExtract(Name, C);
433-
break;
434-
}
423+
switch (Operation) {
424+
default:
425+
llvm_unreachable("Not a read operation");
426+
case Print:
427+
doPrint(Name, C);
428+
break;
429+
case DisplayTable:
430+
doDisplayTable(Name, C);
431+
break;
432+
case Extract:
433+
doExtract(Name, C);
434+
break;
435435
}
436-
failIfError(std::move(Err));
437436
}
438-
439437
if (Members.empty())
440438
return;
441439
for (StringRef Name : Members)
@@ -533,8 +531,9 @@ computeNewArchiveMembers(ArchiveOperation Operation,
533531
int InsertPos = -1;
534532
StringRef PosName = sys::path::filename(RelPos);
535533
if (OldArchive) {
536-
Error Err;
537-
for (auto &Child : OldArchive->children(Err)) {
534+
for (auto &ChildOrErr : OldArchive->children()) {
535+
failIfError(ChildOrErr.getError());
536+
auto &Child = ChildOrErr.get();
538537
int Pos = Ret.size();
539538
ErrorOr<StringRef> NameOrErr = Child.getName();
540539
failIfError(NameOrErr.getError());
@@ -569,7 +568,6 @@ computeNewArchiveMembers(ArchiveOperation Operation,
569568
if (MemberI != Members.end())
570569
Members.erase(MemberI);
571570
}
572-
failIfError(std::move(Err));
573571
}
574572

575573
if (Operation == Delete)
@@ -766,11 +764,9 @@ static void runMRIScript() {
766764
"Could not parse library");
767765
Archives.push_back(std::move(*LibOrErr));
768766
object::Archive &Lib = *Archives.back();
769-
{
770-
Error Err;
771-
for (auto &Member : Lib.children(Err))
772-
addMember(NewMembers, Member);
773-
failIfError(std::move(Err));
767+
for (auto &MemberOrErr : Lib.children()) {
768+
failIfError(MemberOrErr.getError());
769+
addMember(NewMembers, *MemberOrErr);
774770
}
775771
break;
776772
}

0 commit comments

Comments
 (0)