diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 10:51:19 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 10:51:19 +0000 | 
| commit | eb11fae6d08f479c0799db45860a98af528fa6e7 (patch) | |
| tree | 44d492a50c8c1a7eb8e2d17ea3360ec4d066f042 /lib/Support/ErrorHandling.cpp | |
| parent | b8a2042aa938069e862750553db0e4d82d25822c (diff) | |
Notes
Diffstat (limited to 'lib/Support/ErrorHandling.cpp')
| -rw-r--r-- | lib/Support/ErrorHandling.cpp | 35 | 
1 files changed, 34 insertions, 1 deletions
| diff --git a/lib/Support/ErrorHandling.cpp b/lib/Support/ErrorHandling.cpp index fb8ae4c1cd5e..21712c5c039e 100644 --- a/lib/Support/ErrorHandling.cpp +++ b/lib/Support/ErrorHandling.cpp @@ -175,6 +175,39 @@ void llvm::report_bad_alloc_error(const char *Reason, bool GenCrashDiag) {  #endif  } +#ifdef LLVM_ENABLE_EXCEPTIONS +// Do not set custom new handler if exceptions are enabled. In this case OOM +// errors are handled by throwing 'std::bad_alloc'. +void llvm::install_out_of_memory_new_handler() { +} +#else +// Causes crash on allocation failure. It is called prior to the handler set by +// 'install_bad_alloc_error_handler'. +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'. +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; +  } +} + +// 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,                                       unsigned line) {    // This code intentionally doesn't call the ErrorHandler callback, because @@ -210,7 +243,7 @@ void LLVMResetFatalErrorHandler() {    remove_fatal_error_handler();  } -#ifdef LLVM_ON_WIN32 +#ifdef _WIN32  #include <winerror.h> | 
