[PATCH] Add a new routine to libc++abi to get the number of uncaught exceptions

Marshall Clow mclow.lists at gmail.com
Fri May 29 16:09:39 PDT 2015


Added basic tests. 
Bumped the version # for libc++abi


http://reviews.llvm.org/D10067

Files:
  include/cxxabi.h
  src/cxa_exception.cpp
  test/uncaught_exceptions.pass.cpp

Index: include/cxxabi.h
===================================================================
--- include/cxxabi.h
+++ include/cxxabi.h
@@ -20,7 +20,7 @@
 
 #include <__cxxabi_config.h>
 
-#define _LIBCPPABI_VERSION 1001
+#define _LIBCPPABI_VERSION 1002
 #define LIBCXXABI_NORETURN  __attribute__((noreturn))
 
 #ifdef __cplusplus
@@ -161,8 +161,9 @@
 extern void __cxa_increment_exception_refcount(void* primary_exception) throw();
 extern void __cxa_decrement_exception_refcount(void* primary_exception) throw();
 
-// Apple addition to support std::uncaught_exception()
-extern bool __cxa_uncaught_exception() throw();
+// Apple extension to support std::uncaught_exception()
+extern bool          __cxa_uncaught_exception () throw();
+extern unsigned int  __cxa_uncaught_exceptions() throw();
 
 #ifdef __linux__
 // Linux TLS support. Not yet an official part of the Itanium ABI.
Index: src/cxa_exception.cpp
===================================================================
--- src/cxa_exception.cpp
+++ src/cxa_exception.cpp
@@ -710,13 +710,16 @@
 }
 
 bool
-__cxa_uncaught_exception() throw()
+__cxa_uncaught_exception() throw() { return __cxa_uncaught_exceptions() != 0; }
+
+unsigned int
+__cxa_uncaught_exceptions() throw()
 {
     // This does not report foreign exceptions in flight
     __cxa_eh_globals* globals = __cxa_get_globals_fast();
     if (globals == 0)
         return false;
-    return globals->uncaughtExceptions != 0;
+    return globals->uncaughtExceptions;
 }
 
 }  // extern "C"
Index: test/uncaught_exceptions.pass.cpp
===================================================================
--- test/uncaught_exceptions.pass.cpp
+++ test/uncaught_exceptions.pass.cpp
@@ -0,0 +1,36 @@
+//===------------------------- catch_ptr_02.cpp ---------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include <cxxabi.h>
+#include <exception>
+#include <cassert>
+
+// namespace __cxxabiv1 {
+//      extern bool          __cxa_uncaught_exception () throw();
+//      extern unsigned int  __cxa_uncaught_exceptions() throw();
+// }
+
+struct A {
+    ~A() { assert( __cxxabiv1::__cxa_uncaught_exception()); }
+    };
+
+struct B {
+    B(int cnt) : data_(cnt) {}
+    ~B() { assert( data_ == __cxxabiv1::__cxa_uncaught_exceptions()); }
+    int data_;
+    };
+
+int main ()
+{
+    try { A a; throw 3; assert (false); }
+    catch (int) {}
+    
+    try { B b(1); throw 3; assert (false); }
+    catch (int) {}
+}

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10067.26834.patch
Type: text/x-patch
Size: 2695 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150529/ae79f186/attachment.bin>


More information about the cfe-commits mailing list