[PATCH] D20784: [libcxx][libcxxabi] Decouple no-exceptions libcpp variant from cxa_exception.cpp and cxa_personality.cpp of libcxxabi

Asiri Rathnayake via cfe-commits cfe-commits at lists.llvm.org
Sun May 29 17:39:18 PDT 2016


rmaprath created this revision.
rmaprath added reviewers: EricWF, mclow.lists.
rmaprath added a subscriber: cfe-commits.

This is a pre-requisite to address a review comment on D20677; The `no-exceptions` variant of libcxxabi should not be allowed to be linked against code that requires exceptions.

In order to do this, we need to rip off some exceptions-related symbols from the no-exceptions libcxxabi build. We can get rid of both `cxa_exception.cpp` and `cxa_personality.cpp` to meet the said requirement, but this needs a small surgery to the `no-exception` libcpp variant; we must `#ifdef` out the dependency on these two libcxxabi sources from the `exception.cpp` of libcxx.

http://reviews.llvm.org/D20784

Files:
  src/exception.cpp

Index: src/exception.cpp
===================================================================
--- src/exception.cpp
+++ src/exception.cpp
@@ -106,6 +106,9 @@
 
 int uncaught_exceptions() _NOEXCEPT
 {
+#ifdef _LIBCPP_NO_EXCEPTIONS
+    return 0;
+#endif
 #if defined(__APPLE__) || defined(_LIBCPPABI_VERSION)
    // on Darwin, there is a helper function so __cxa_get_globals is private
 # if _LIBCPPABI_VERSION > 1101
@@ -183,7 +186,9 @@
 exception_ptr::~exception_ptr() _NOEXCEPT
 {
 #if HAVE_DEPENDENT_EH_ABI
+#   ifndef _LIBCPP_NO_EXCEPTIONS
     __cxa_decrement_exception_refcount(__ptr_);
+#   endif
 #elif defined(__GLIBCXX__)
     reinterpret_cast<__exception_ptr::exception_ptr*>(this)->~exception_ptr();
 #else
@@ -201,7 +206,9 @@
     : __ptr_(other.__ptr_)
 {
 #if HAVE_DEPENDENT_EH_ABI
+#   ifndef _LIBCPP_NO_EXCEPTIONS
     __cxa_increment_exception_refcount(__ptr_);
+#   endif
 #elif defined(__GLIBCXX__)
     new (reinterpret_cast<void*>(this)) __exception_ptr::exception_ptr(
         reinterpret_cast<const __exception_ptr::exception_ptr&>(other));
@@ -221,8 +228,10 @@
 #if HAVE_DEPENDENT_EH_ABI
     if (__ptr_ != other.__ptr_)
     {
+#       ifndef _LIBCPP_NO_EXCEPTIONS
         __cxa_increment_exception_refcount(other.__ptr_);
         __cxa_decrement_exception_refcount(__ptr_);
+#       endif
         __ptr_ = other.__ptr_;
     }
     return *this;
@@ -272,7 +281,9 @@
     // this whole function would be just:
     //    return exception_ptr(__cxa_current_primary_exception());
     exception_ptr ptr;
+#ifndef _LIBCPP_NO_EXCEPTIONS
     ptr.__ptr_ = __cxa_current_primary_exception();
+#endif
     return ptr;
 #else
 #   if defined(_MSC_VER) && ! defined(__clang__)
@@ -291,7 +302,9 @@
 void rethrow_exception(exception_ptr p)
 {
 #if HAVE_DEPENDENT_EH_ABI
+#ifndef _LIBCPP_NO_EXCEPTIONS
     __cxa_rethrow_primary_exception(p.__ptr_);
+#endif
     // if p.__ptr_ is NULL, above returns so we terminate
     terminate();
 #elif defined(__GLIBCXX__)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20784.58925.patch
Type: text/x-patch
Size: 1980 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160530/14d22bbb/attachment.bin>


More information about the cfe-commits mailing list