Index: lib/Support/ErrorHandling.cpp =================================================================== --- lib/Support/ErrorHandling.cpp +++ lib/Support/ErrorHandling.cpp @@ -186,25 +186,11 @@ 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::set_new_handler(out_of_memory_new_handler); } - -// 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, Index: lib/Support/InitLLVM.cpp =================================================================== --- lib/Support/InitLLVM.cpp +++ lib/Support/InitLLVM.cpp @@ -23,6 +23,7 @@ InitLLVM::InitLLVM(int &Argc, const char **&Argv) : StackPrinter(Argc, Argv) { sys::PrintStackTraceOnErrorSignal(Argv[0]); + install_out_of_memory_new_handler(); #ifdef _WIN32 // We use UTF-8 as the internal character encoding. On Windows,