diff options
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp | 9 | ||||
| -rw-r--r-- | llvm/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h | 9 | ||||
| -rw-r--r-- | llvm/lib/Object/Archive.cpp | 48 | ||||
| -rw-r--r-- | llvm/lib/Support/Error.cpp | 11 |
4 files changed, 47 insertions, 30 deletions
diff --git a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp index 30f18db0a46..9da0045d201 100644 --- a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp +++ b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp @@ -327,13 +327,14 @@ RuntimeDyld::SymbolInfo MCJIT::findSymbol(const std::string &Name, for (object::OwningBinary<object::Archive> &OB : Archives) { object::Archive *A = OB.getBinary(); // Look for our symbols in each Archive - object::Archive::child_iterator ChildIt = A->findSym(Name); - if (std::error_code EC = ChildIt->getError()) - report_fatal_error(EC.message()); + Error Err; + object::Archive::child_iterator ChildIt = A->findSym(Err, Name); + if (Err) + report_fatal_error(std::move(Err)); if (ChildIt != A->child_end()) { // FIXME: Support nested archives? Expected<std::unique_ptr<object::Binary>> ChildBinOrErr = - (*ChildIt)->getAsBinary(); + ChildIt->getAsBinary(); if (!ChildBinOrErr) { // TODO: Actually report errors helpfully. consumeError(ChildBinOrErr.takeError()); diff --git a/llvm/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h b/llvm/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h index 5ab47b97dbd..2fde56447fc 100644 --- a/llvm/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h +++ b/llvm/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h @@ -258,13 +258,14 @@ private: for (object::OwningBinary<object::Archive> &OB : Archives) { object::Archive *A = OB.getBinary(); // Look for our symbols in each Archive - object::Archive::child_iterator ChildIt = A->findSym(Name); - if (std::error_code EC = ChildIt->getError()) - report_fatal_error(EC.message()); + Error Err; + object::Archive::child_iterator ChildIt = A->findSym(Err, Name); + if (Err) + report_fatal_error(std::move(Err)); if (ChildIt != A->child_end()) { // FIXME: Support nested archives? Expected<std::unique_ptr<object::Binary>> ChildBinOrErr = - (*ChildIt)->getAsBinary(); + ChildIt->getAsBinary(); if (!ChildBinOrErr) { // TODO: Actually report errors helpfully. consumeError(ChildBinOrErr.takeError()); diff --git a/llvm/lib/Object/Archive.cpp b/llvm/lib/Object/Archive.cpp index 4720bf894e9..4827e58f5d3 100644 --- a/llvm/lib/Object/Archive.cpp +++ b/llvm/lib/Object/Archive.cpp @@ -298,12 +298,9 @@ Archive::Archive(MemoryBufferRef Source, Error &Err) } // Get the special members. - child_iterator I = child_begin(false); - std::error_code ec; - if ((ec = I->getError())) { - Err = errorCodeToError(ec); + child_iterator I = child_begin(Err, false); + if (Err) return; - } child_iterator E = child_end(); // This is at least a valid empty archive. Since an empty archive is the @@ -315,13 +312,13 @@ Archive::Archive(MemoryBufferRef Source, Error &Err) Err = Error::success(); return; } - const Child *C = &**I; + const Child *C = &*I; auto Increment = [&]() { ++I; - if ((Err = errorCodeToError(I->getError()))) + if (Err) return true; - C = &**I; + C = &*I; return false; }; @@ -366,8 +363,7 @@ Archive::Archive(MemoryBufferRef Source, Error &Err) Format = K_BSD; // We know this is BSD, so getName will work since there is no string table. ErrorOr<StringRef> NameOrErr = C->getName(); - ec = NameOrErr.getError(); - if (ec) { + if (auto ec = NameOrErr.getError()) { Err = errorCodeToError(ec); return; } @@ -465,23 +461,29 @@ Archive::Archive(MemoryBufferRef Source, Error &Err) Err = Error::success(); } -Archive::child_iterator Archive::child_begin(bool SkipInternal) const { +Archive::child_iterator Archive::child_begin(Error &Err, + bool SkipInternal) const { if (Data.getBufferSize() == 8) // empty archive. return child_end(); if (SkipInternal) - return Child(this, FirstRegularData, FirstRegularStartOfFile); + return child_iterator(Child(this, FirstRegularData, + FirstRegularStartOfFile), + &Err); const char *Loc = Data.getBufferStart() + strlen(Magic); std::error_code EC; - Child c(this, Loc, &EC); - if (EC) - return child_iterator(EC); - return child_iterator(c); + Child C(this, Loc, &EC); + if (EC) { + ErrorAsOutParameter ErrAsOutParam(Err); + Err = errorCodeToError(EC); + return child_end(); + } + return child_iterator(C, &Err); } Archive::child_iterator Archive::child_end() const { - return Child(this, nullptr, nullptr); + return child_iterator(Child(this, nullptr, nullptr), nullptr); } StringRef Archive::Symbol::getName() const { @@ -665,18 +667,20 @@ uint32_t Archive::getNumberOfSymbols() const { return read32le(buf); } -Archive::child_iterator Archive::findSym(StringRef name) const { +Archive::child_iterator Archive::findSym(Error &Err, StringRef name) const { Archive::symbol_iterator bs = symbol_begin(); Archive::symbol_iterator es = symbol_end(); for (; bs != es; ++bs) { StringRef SymName = bs->getName(); if (SymName == name) { - ErrorOr<Archive::child_iterator> ResultOrErr = bs->getMember(); - // FIXME: Should we really eat the error? - if (ResultOrErr.getError()) + if (auto MemberOrErr = bs->getMember()) { + return child_iterator(*MemberOrErr, &Err); + } else { + ErrorAsOutParameter ErrAsOutParam(Err); + Err = errorCodeToError(MemberOrErr.getError()); return child_end(); - return ResultOrErr.get(); + } } } return child_end(); diff --git a/llvm/lib/Support/Error.cpp b/llvm/lib/Support/Error.cpp index df540d10bc5..6b22691eb1a 100644 --- a/llvm/lib/Support/Error.cpp +++ b/llvm/lib/Support/Error.cpp @@ -64,6 +64,7 @@ void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner) { }); } + std::error_code ErrorList::convertToErrorCode() const { return std::error_code(static_cast<int>(ErrorErrorCode::MultipleErrors), *ErrorErrorCat); @@ -99,4 +100,14 @@ std::error_code StringError::convertToErrorCode() const { return EC; } +void report_fatal_error(Error Err, bool GenCrashDiag) { + assert(Err && "report_fatal_error called with success value"); + std::string ErrMsg; + { + raw_string_ostream ErrStream(ErrMsg); + logAllUnhandledErrors(std::move(Err), ErrStream, ""); + } + report_fatal_error(ErrMsg); +} + } |

