summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/ErrorHandling.cpp
diff options
context:
space:
mode:
authorFangrui Song <maskray@google.com>2019-07-12 16:23:25 +0000
committerFangrui Song <maskray@google.com>2019-07-12 16:23:25 +0000
commite99dee82b0bd90e3f51482de3b18a4ae0e040eb6 (patch)
tree2ab92804d1c48613a72f9ebd77e1062b7fd5bb87 /llvm/lib/Support/ErrorHandling.cpp
parentf72fd0fada5d41b8362e7ea95b1f63806c08a21e (diff)
downloadbcm5719-llvm-e99dee82b0bd90e3f51482de3b18a4ae0e040eb6.tar.gz
bcm5719-llvm-e99dee82b0bd90e3f51482de3b18a4ae0e040eb6.zip
[Support] Move the static initializer install_out_memory_new_handler to InitLLVM
An application linking against LLVMSupport should not get the gratuitous set::std_new_handler call. Reviewed By: jfb Differential Revision: https://reviews.llvm.org/D64505 llvm-svn: 365915
Diffstat (limited to 'llvm/lib/Support/ErrorHandling.cpp')
-rw-r--r--llvm/lib/Support/ErrorHandling.cpp22
1 files changed, 5 insertions, 17 deletions
diff --git a/llvm/lib/Support/ErrorHandling.cpp b/llvm/lib/Support/ErrorHandling.cpp
index 27b48670ac0..0f13f7a536f 100644
--- a/llvm/lib/Support/ErrorHandling.cpp
+++ b/llvm/lib/Support/ErrorHandling.cpp
@@ -186,25 +186,13 @@ static void out_of_memory_new_handler() {
llvm::report_bad_alloc_error("Allocation failed");
}
-// Installs new handler that causes crash on allocation failure. It does not
-// need to be called explicitly, if this file is linked to application, because
-// in this case it is called during construction of 'new_handler_installer'.
+// Installs new handler that causes crash on allocation failure. It is called by
+// InitLLVM.
void llvm::install_out_of_memory_new_handler() {
- static bool out_of_memory_new_handler_installed = false;
- if (!out_of_memory_new_handler_installed) {
- std::set_new_handler(out_of_memory_new_handler);
- out_of_memory_new_handler_installed = true;
- }
+ std::new_handler old = std::set_new_handler(out_of_memory_new_handler);
+ (void)old;
+ assert(old == nullptr && "new-handler already installed");
}
-
-// Static object that causes installation of 'out_of_memory_new_handler' before
-// execution of 'main'.
-static class NewHandlerInstaller {
-public:
- NewHandlerInstaller() {
- install_out_of_memory_new_handler();
- }
-} new_handler_installer;
#endif
void llvm::llvm_unreachable_internal(const char *msg, const char *file,
OpenPOWER on IntegriCloud