Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion llvm/lib/Support/ErrorHandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ void llvm::install_bad_alloc_error_handler(fatal_error_handler_t handler,
#if LLVM_ENABLE_THREADS == 1
std::lock_guard<std::mutex> Lock(BadAllocErrorHandlerMutex);
#endif
assert(!ErrorHandler && "Bad alloc error handler already registered!\n");
assert(!BadAllocErrorHandler &&
"Bad alloc error handler already registered!\n");
BadAllocErrorHandler = handler;
BadAllocErrorHandlerUserData = user_data;
}
Expand Down
22 changes: 22 additions & 0 deletions llvm/unittests/Support/ErrorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1132,4 +1132,26 @@ TEST(Error, moveInto) {
}
}

TEST(Error, FatalBadAllocErrorHandlersInteraction) {
auto ErrorHandler = [](void *Data, const char *, bool) {};
install_fatal_error_handler(ErrorHandler, nullptr);
// The following call should not crash
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should expand just a little more your comment, just to explain we're doing this sequence of calls because of a bug that happened previously inside install_bad_alloc_error_handler.

install_bad_alloc_error_handler(ErrorHandler, nullptr);

// Don't interfere with other tests:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove : and finish with a full stop (.)

remove_fatal_error_handler();
remove_bad_alloc_error_handler();
}

TEST(Error, BadAllocFatalErrorHandlersInteraction) {
auto ErrorHandler = [](void *Data, const char *, bool) {};
install_bad_alloc_error_handler(ErrorHandler, nullptr);
// The following call should not crash
install_fatal_error_handler(ErrorHandler, nullptr);

// Don't interfere with other tests:
remove_fatal_error_handler();
remove_bad_alloc_error_handler();
}

} // namespace