Skip to content

Commit

Permalink
[cling] Always handle Error of createObjectFile
Browse files Browse the repository at this point in the history
This avoids test failures because the destructor of llvm::Error aborts
he program "due to an unhandled Error", which can happen in case of
race conditions with concurrent file operations in a directory.
  • Loading branch information
hahnjo committed Dec 7, 2024
1 parent 4e7b4bc commit 8fcd2a8
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions interpreter/cling/lib/Interpreter/DynamicLibraryManagerSymbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,11 +748,14 @@ namespace cling {
auto ObjFileOrErr =
llvm::object::ObjectFile::createObjectFile(FileName);
if (llvm::Error Err = ObjFileOrErr.takeError()) {
// Note: It is important to always call handleAllErrors, otherwise
// the destructor of llvm::Error will abort the program "due to an
// unhandled Error"
std::string Message;
handleAllErrors(std::move(Err), [&](llvm::ErrorInfoBase& EIB) {
Message += EIB.message() + "; ";
});
if (DEBUG > 1) {
std::string Message;
handleAllErrors(std::move(Err), [&](llvm::ErrorInfoBase &EIB) {
Message += EIB.message() + "; ";
});
cling::errs()
<< "Dyld::ScanForLibraries: Failed to read object file "
<< FileName.str() << " Errors: " << Message << "\n";
Expand Down Expand Up @@ -1007,11 +1010,14 @@ namespace cling {

auto ObjF = llvm::object::ObjectFile::createObjectFile(library_filename);
if (llvm::Error Err = ObjF.takeError()) {
// Note: It is important to always call handleAllErrors, otherwise the
// destructor of llvm::Error will abort the program "due to an unhandled
// Error"
std::string Message;
handleAllErrors(std::move(Err), [&](llvm::ErrorInfoBase& EIB) {
Message += EIB.message() + "; ";
});
if (DEBUG > 1) {
std::string Message;
handleAllErrors(std::move(Err), [&](llvm::ErrorInfoBase &EIB) {
Message += EIB.message() + "; ";
});
cling::errs() << "Dyld::ContainsSymbol: Failed to read object file "
<< library_filename << " Errors: " << Message << "\n";
}
Expand Down Expand Up @@ -1141,6 +1147,9 @@ namespace cling {

auto ObjF = llvm::object::ObjectFile::createObjectFile(FileName);
if (!ObjF) {
// Note: It is important to always call handleAllErrors, otherwise the
// destructor of llvm::Error will abort the program "due to an unhandled
// Error"
std::string Message;
handleAllErrors(ObjF.takeError(), [&](llvm::ErrorInfoBase &EIB) {
Message += EIB.message() + "; ";
Expand Down

0 comments on commit 8fcd2a8

Please sign in to comment.