diff --git a/libcxxabi/src/cxa_default_handlers.cpp b/libcxxabi/src/cxa_default_handlers.cpp --- a/libcxxabi/src/cxa_default_handlers.cpp +++ b/libcxxabi/src/cxa_default_handlers.cpp @@ -40,10 +40,6 @@ using namespace __cxxabiv1; __cxa_eh_globals* globals = __cxa_get_globals_fast(); - // If there is no uncaught exception, just note that we're terminating - if (!globals) - abort_message("terminating"); - __cxa_exception* exception_header = globals->caughtExceptions; if (!exception_header) abort_message("terminating"); diff --git a/libcxxabi/src/cxa_exception.cpp b/libcxxabi/src/cxa_exception.cpp --- a/libcxxabi/src/cxa_exception.cpp +++ b/libcxxabi/src/cxa_exception.cpp @@ -512,7 +512,7 @@ __builtin_offsetof(__cxa_dependent_exception, handlerCount), "the layout of __cxa_exception must match the layout of " "__cxa_dependent_exception"); - __cxa_eh_globals* globals = __cxa_get_globals_fast(); // __cxa_get_globals called in __cxa_begin_catch + __cxa_eh_globals* globals = __cxa_get_globals_fast(); __cxa_exception* exception_header = globals->caughtExceptions; // If we've rethrown a foreign exception, then globals->caughtExceptions // will have been made an empty stack by __cxa_rethrow() and there is @@ -579,8 +579,6 @@ std::type_info *__cxa_current_exception_type() { // get the current exception __cxa_eh_globals *globals = __cxa_get_globals_fast(); - if (NULL == globals) - return NULL; // If there have never been any exceptions, there are none now. __cxa_exception *exception_header = globals->caughtExceptions; if (NULL == exception_header) return NULL; // No current exception @@ -682,16 +680,10 @@ caughtExceptions stack. Atomically increment the exception's referenceCount. If there is no such thrown object or if the thrown object is foreign, returns null. - - We can use __cxa_get_globals_fast here to get the globals because if there have - been no exceptions thrown, ever, on this thread, we can return NULL without - the need to allocate the exception-handling globals. */ void *__cxa_current_primary_exception() throw() { // get the current exception __cxa_eh_globals* globals = __cxa_get_globals_fast(); - if (NULL == globals) - return NULL; // If there are no globals, there is no exception __cxa_exception* exception_header = globals->caughtExceptions; if (NULL == exception_header) return NULL; // No current exception @@ -766,8 +758,6 @@ { // This does not report foreign exceptions in flight __cxa_eh_globals* globals = __cxa_get_globals_fast(); - if (globals == 0) - return 0; return globals->uncaughtExceptions; } diff --git a/libcxxabi/src/cxa_handlers.cpp b/libcxxabi/src/cxa_handlers.cpp --- a/libcxxabi/src/cxa_handlers.cpp +++ b/libcxxabi/src/cxa_handlers.cpp @@ -77,16 +77,13 @@ // If there might be an uncaught exception using namespace __cxxabiv1; __cxa_eh_globals* globals = __cxa_get_globals_fast(); - if (globals) + __cxa_exception* exception_header = globals->caughtExceptions; + if (exception_header) { - __cxa_exception* exception_header = globals->caughtExceptions; - if (exception_header) - { - _Unwind_Exception* unwind_exception = - reinterpret_cast<_Unwind_Exception*>(exception_header + 1) - 1; - if (__isOurExceptionClass(unwind_exception)) - __terminate(exception_header->terminateHandler); - } + _Unwind_Exception* unwind_exception = + reinterpret_cast<_Unwind_Exception*>(exception_header + 1) - 1; + if (__isOurExceptionClass(unwind_exception)) + __terminate(exception_header->terminateHandler); } #endif __terminate(get_terminate()); diff --git a/libcxxabi/test/test_exception_storage.pass.cpp b/libcxxabi/test/test_exception_storage.pass.cpp --- a/libcxxabi/test/test_exception_storage.pass.cpp +++ b/libcxxabi/test/test_exception_storage.pass.cpp @@ -27,11 +27,11 @@ int thread_id = 0; #endif - globals = __cxxabiv1::__cxa_get_globals(); - if (!globals) - std::cerr << "Got null result from __cxa_get_globals on thread " << thread_id << "\n"; - void* fast_globals = __cxxabiv1::__cxa_get_globals_fast(); + if (!fast_globals) + std::cerr << "Got null result from __cxa_get_globals_fast on thread " << thread_id << "\n"; + + globals = __cxxabiv1::__cxa_get_globals(); if (globals != fast_globals) { std::cerr << "__cxa_get_globals returned " << globals << " but __cxa_get_globals_fast returned " << fast_globals << " on thread " << thread_id << "\n"; @@ -55,7 +55,7 @@ thread.join(); for (int i = 0; i < num_threads; ++i) { - // Either __cxa_get_globals was nullptr or __cxa_get_globals_fast returned a + // Either __cxa_get_globals_fast was nullptr or __cxa_get_globals returned a // different value. We already diagnosed both in the thread. if (!thread_globals[i]) return 1;