[cfe-commits] [libcxxabi] r148830 - in /libcxxabi/trunk/src: cxa_handlers.cpp cxa_handlers.hpp

Howard Hinnant hhinnant at apple.com
Tue Jan 24 10:26:29 PST 2012


Author: hhinnant
Date: Tue Jan 24 12:26:29 2012
New Revision: 148830

URL: http://llvm.org/viewvc/llvm-project?rev=148830&view=rev
Log:
Remove dependence upon std::exception_ptr from the default_terminate_handler.  Recovered the equivalent functionality at a lower level.

Modified:
    libcxxabi/trunk/src/cxa_handlers.cpp
    libcxxabi/trunk/src/cxa_handlers.hpp

Modified: libcxxabi/trunk/src/cxa_handlers.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_handlers.cpp?rev=148830&r1=148829&r2=148830&view=diff
==============================================================================
--- libcxxabi/trunk/src/cxa_handlers.cpp (original)
+++ libcxxabi/trunk/src/cxa_handlers.cpp Tue Jan 24 12:26:29 2012
@@ -14,7 +14,10 @@
 #include <new>
 #include <exception>
 #include "abort_message.h"
+#include "cxxabi.h"
 #include "cxa_handlers.hpp"
+#include "cxa_exception.hpp"
+#include "private_typeinfo.h"
 
 namespace std
 {
@@ -23,23 +26,39 @@
 
 static void default_terminate_handler()
 {
-    std::exception_ptr cp = std::current_exception();
-    if (cp)
+    // If there might be an uncaught exception
+    using namespace __cxxabiv1;
+    __cxa_eh_globals* globals = __cxa_get_globals_fast();
+    if (globals)
     {
-        try
+        __cxa_exception* exception_header = globals->caughtExceptions;
+        // If there is an uncaught exception
+        if (exception_header)
         {
-            rethrow_exception(cp);
-        }
-        catch (const std::exception& e)
-        {
-            abort_message("terminating with %s exception: %s\n", cause, e.what());
-        }
-        catch (...)
-        {
-            abort_message("terminating with %s exception\n", cause);
+            _Unwind_Exception* unwind_exception =
+                reinterpret_cast<_Unwind_Exception*>(exception_header + 1) - 1;
+            void* thrown_object =
+                unwind_exception->exception_class == kOurDependentExceptionClass ?
+                    ((__cxa_dependent_exception*)exception_header)->primaryException :
+                    exception_header + 1;
+            const __shim_type_info* thrown_type =
+                static_cast<const __shim_type_info*>(exception_header->exceptionType);
+            const __shim_type_info* catch_type =
+                static_cast<const __shim_type_info*>(&typeid(exception));
+            // If the uncaught exception can be caught with std::exception&
+            if (catch_type->can_catch(thrown_type, thrown_object))
+            {
+                // Include the what() message from the exception
+                const exception* e = static_cast<const exception*>(thrown_object);
+                abort_message("terminating with %s exception: %s", cause, e->what());
+            }
+            else
+                // Else just note that we're terminating with an exception
+                abort_message("terminating with %s exception", cause);
         }
     }
-    abort_message("terminating\n");
+    // Else just note that we're terminating
+    abort_message("terminating");
 }
 
 static void default_unexpected_handler()
@@ -66,8 +85,7 @@
     return __sync_fetch_and_add(&__unexpected_handler, (unexpected_handler)0);
 }
 
-_LIBCPP_HIDDEN
-_ATTRIBUTE(noreturn)
+__attribute__((visibility("hidden"), noreturn))
 void
 __unexpected(unexpected_handler func)
 {
@@ -76,7 +94,7 @@
     abort_message("unexpected_handler unexpectedly returned");
 }
 
-_ATTRIBUTE(noreturn)
+__attribute__((noreturn))
 void
 unexpected()
 {
@@ -97,8 +115,7 @@
     return __sync_fetch_and_add(&__terminate_handler, (terminate_handler)0);
 }
 
-_LIBCPP_HIDDEN
-_ATTRIBUTE(noreturn)
+__attribute__((visibility("hidden"), noreturn))
 void
 __terminate(terminate_handler func) _NOEXCEPT
 {
@@ -119,7 +136,7 @@
 #endif  // #if __has_feature(cxx_exceptions)
 }
 
-_ATTRIBUTE(noreturn)
+__attribute__((noreturn))
 void
 terminate() _NOEXCEPT
 {

Modified: libcxxabi/trunk/src/cxa_handlers.hpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_handlers.hpp?rev=148830&r1=148829&r2=148830&view=diff
==============================================================================
--- libcxxabi/trunk/src/cxa_handlers.hpp (original)
+++ libcxxabi/trunk/src/cxa_handlers.hpp Tue Jan 24 12:26:29 2012
@@ -15,13 +15,11 @@
 namespace std
 {
 
-_LIBCPP_HIDDEN
-_ATTRIBUTE(noreturn)
+__attribute__((visibility("hidden"), noreturn))
 void
 __unexpected(unexpected_handler func);
 
-_LIBCPP_HIDDEN
-_ATTRIBUTE(noreturn)
+__attribute__((visibility("hidden"), noreturn))
 void
 __terminate(terminate_handler func) _NOEXCEPT;
 





More information about the cfe-commits mailing list