[libcxxabi] r238827 - Implement uncaught_exceptions() to get a count, rather than a bool. Update the libc++abi version. Reviewed as http://reviews.llvm.org/D10067

Marshall Clow mclow.lists at gmail.com
Tue Jun 2 06:03:18 PDT 2015


Author: marshall
Date: Tue Jun  2 08:03:17 2015
New Revision: 238827

URL: http://llvm.org/viewvc/llvm-project?rev=238827&view=rev
Log:
Implement uncaught_exceptions() to get a count, rather than a bool. Update the libc++abi version. Reviewed as http://reviews.llvm.org/D10067

Added:
    libcxxabi/trunk/test/uncaught_exceptions.pass.cpp
Modified:
    libcxxabi/trunk/include/cxxabi.h
    libcxxabi/trunk/src/cxa_exception.cpp

Modified: libcxxabi/trunk/include/cxxabi.h
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/include/cxxabi.h?rev=238827&r1=238826&r2=238827&view=diff
==============================================================================
--- libcxxabi/trunk/include/cxxabi.h (original)
+++ libcxxabi/trunk/include/cxxabi.h Tue Jun  2 08:03:17 2015
@@ -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_rethrow_primary_except
 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.

Modified: libcxxabi/trunk/src/cxa_exception.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_exception.cpp?rev=238827&r1=238826&r2=238827&view=diff
==============================================================================
--- libcxxabi/trunk/src/cxa_exception.cpp (original)
+++ libcxxabi/trunk/src/cxa_exception.cpp Tue Jun  2 08:03:17 2015
@@ -710,13 +710,16 @@ __cxa_rethrow_primary_exception(void* th
 }
 
 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 0;
+    return globals->uncaughtExceptions;
 }
 
 }  // extern "C"

Added: libcxxabi/trunk/test/uncaught_exceptions.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/uncaught_exceptions.pass.cpp?rev=238827&view=auto
==============================================================================
--- libcxxabi/trunk/test/uncaught_exceptions.pass.cpp (added)
+++ libcxxabi/trunk/test/uncaught_exceptions.pass.cpp Tue Jun  2 08:03:17 2015
@@ -0,0 +1,36 @@
+//===------------------- uncaught_exceptions.pass.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) {}
+}





More information about the cfe-commits mailing list