aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Support/ErrorTest.cpp
diff options
context:
space:
mode:
authorFabian Schiebel <52407375+fabianbs96@users.noreply.github.com>2024-03-01 20:53:54 +0100
committerGitHub <noreply@github.com>2024-03-01 14:53:54 -0500
commit1685e7fdab3f1b3fc654f7c93219594532becb81 (patch)
treebbeb487147599302d750dba831f999fdda4fbd4d /llvm/unittests/Support/ErrorTest.cpp
parent1a0c988ebddd83bd34393a1500b5f3ce80888fbc (diff)
downloadllvm-1685e7fdab3f1b3fc654f7c93219594532becb81.zip
llvm-1685e7fdab3f1b3fc654f7c93219594532becb81.tar.gz
llvm-1685e7fdab3f1b3fc654f7c93219594532becb81.tar.bz2
[Support] Fix crash in install_bad_alloc_error_handler (#83160)
Previously, the function `install_bad_alloc_error_handler` was asserting that a bad_alloc error handler was not already installed. However, it was actually checking for the fatal-error handler, not for the bad_alloc error handler, causing an assertion failure if a fatal-error handler was already installed. Fixes #83040
Diffstat (limited to 'llvm/unittests/Support/ErrorTest.cpp')
-rw-r--r--llvm/unittests/Support/ErrorTest.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/llvm/unittests/Support/ErrorTest.cpp b/llvm/unittests/Support/ErrorTest.cpp
index 11f9320..1229282 100644
--- a/llvm/unittests/Support/ErrorTest.cpp
+++ b/llvm/unittests/Support/ErrorTest.cpp
@@ -1132,4 +1132,30 @@ 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; previously, a bug in
+ // install_bad_alloc_error_handler asserted that no fatal-error handler is
+ // installed already.
+ install_bad_alloc_error_handler(ErrorHandler, nullptr);
+
+ // Don't interfere with other tests.
+ 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; related to
+ // FatalBadAllocErrorHandlersInteraction: Ensure that the error does not occur
+ // in the other direction.
+ install_fatal_error_handler(ErrorHandler, nullptr);
+
+ // Don't interfere with other tests.
+ remove_fatal_error_handler();
+ remove_bad_alloc_error_handler();
+}
+
} // namespace