[libcxx-commits] [libcxxabi] 71d88ce - [libc++/libc++abi] Automatically detect whether exceptions are enabled

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jul 3 11:58:19 PDT 2020


Author: Louis Dionne
Date: 2020-07-03T14:58:09-04:00
New Revision: 71d88cebfb42c8c5ac2d54b42afdcca956e55660

URL: https://github.com/llvm/llvm-project/commit/71d88cebfb42c8c5ac2d54b42afdcca956e55660
DIFF: https://github.com/llvm/llvm-project/commit/71d88cebfb42c8c5ac2d54b42afdcca956e55660.diff

LOG: [libc++/libc++abi] Automatically detect whether exceptions are enabled

Instead of detecting it automatically (in libc++) and relying on
_LIBCXXABI_NO_EXCEPTIONS being set explicitly (in libc++abi), always
detect whether exceptions are enabled automatically.

This commit also removes support for specifying -D_LIBCPP_NO_EXCEPTIONS
and -D_LIBCXXABI_NO_EXCEPTIONS explicitly -- those should just be inferred
from using -fno-exceptions (or an equivalent flag).

Allowing both -D_FOO_NO_EXCEPTIONS to be provided explicitly and trying
to detect it automatically is just confusing, especially since we did
specify it explicitly when building libc++abi. We should have only one
way to detect whether exceptions are enabled, but it should be robust.

Added: 
    

Modified: 
    libcxx/CMakeLists.txt
    libcxx/include/__config
    libcxx/test/libcxx/strings/iterators.noexcept.pass.cpp
    libcxxabi/CMakeLists.txt
    libcxxabi/include/__cxxabi_config.h
    llvm/utils/gn/secondary/libcxx/src/BUILD.gn

Removed: 
    


################################################################################
diff  --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index 9fb4e40a014a..d215ef6f89d9 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -628,7 +628,6 @@ function(cxx_add_exception_flags target)
     # functions never throw a C++ exception.
     target_add_compile_flags_if_supported(${target} PUBLIC -EHsc)
   else()
-    target_compile_definitions(${target} PUBLIC -D_LIBCPP_NO_EXCEPTIONS)
     target_add_compile_flags_if_supported(${target} PUBLIC -EHs- -EHa-)
     target_add_compile_flags_if_supported(${target} PUBLIC -fno-exceptions)
   endif()

diff  --git a/libcxx/include/__config b/libcxx/include/__config
index a0de82ce81cf..7e4c37431ea4 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -419,8 +419,8 @@ typedef __char16_t char16_t;
 typedef __char32_t char32_t;
 #endif
 
-#if !(__has_feature(cxx_exceptions)) && !defined(_LIBCPP_NO_EXCEPTIONS)
-#define _LIBCPP_NO_EXCEPTIONS
+#if !__has_feature(cxx_exceptions)
+#  define _LIBCPP_NO_EXCEPTIONS
 #endif
 
 #if !(__has_feature(cxx_rtti)) && !defined(_LIBCPP_NO_RTTI)
@@ -528,8 +528,8 @@ typedef __char32_t char32_t;
 
 #define _LIBCPP_NORETURN __attribute__((noreturn))
 
-#if !__EXCEPTIONS && !defined(_LIBCPP_NO_EXCEPTIONS)
-#define _LIBCPP_NO_EXCEPTIONS
+#if !__EXCEPTIONS
+#  define _LIBCPP_NO_EXCEPTIONS
 #endif
 
 // Determine if GCC supports relaxed constexpr

diff  --git a/libcxx/test/libcxx/strings/iterators.noexcept.pass.cpp b/libcxx/test/libcxx/strings/iterators.noexcept.pass.cpp
index 787b86ad95b9..78f8429598c0 100644
--- a/libcxx/test/libcxx/strings/iterators.noexcept.pass.cpp
+++ b/libcxx/test/libcxx/strings/iterators.noexcept.pass.cpp
@@ -18,7 +18,7 @@
 // When exceptions are disabled, all iterators should get this "fast path"
 //
 
-// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_NO_EXCEPTIONS
+// ADDITIONAL_COMPILE_FLAGS: -fno-exceptions
 
 #include <iterator>
 #include <cassert>

diff  --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt
index c577036064a2..b6f1f0823bb6 100644
--- a/libcxxabi/CMakeLists.txt
+++ b/libcxxabi/CMakeLists.txt
@@ -307,7 +307,6 @@ if (LIBCXXABI_ENABLE_EXCEPTIONS)
   # Do we really need to be run through the C compiler ?
   add_c_compile_flags_if_supported(-funwind-tables)
 else()
-  add_definitions(-D_LIBCXXABI_NO_EXCEPTIONS)
   add_compile_flags_if_supported(-fno-exceptions)
   add_compile_flags_if_supported(-EHs-)
   add_compile_flags_if_supported(-EHa-)

diff  --git a/libcxxabi/include/__cxxabi_config.h b/libcxxabi/include/__cxxabi_config.h
index cbbb1c10c1a2..b5444d67ee44 100644
--- a/libcxxabi/include/__cxxabi_config.h
+++ b/libcxxabi/include/__cxxabi_config.h
@@ -76,4 +76,12 @@
 #  define _LIBCXXABI_GUARD_ABI_ARM
 #endif
 
+#if defined(_LIBCXXABI_COMPILER_CLANG)
+#  if !__has_feature(cxx_exceptions)
+#    define _LIBCXXABI_NO_EXCEPTIONS
+#  endif
+#elif defined(_LIBCXXABI_COMPILER_GCC) && !__EXCEPTIONS
+#  define _LIBCXXABI_NO_EXCEPTIONS
+#endif
+
 #endif // ____CXXABI_CONFIG_H

diff  --git a/llvm/utils/gn/secondary/libcxx/src/BUILD.gn b/llvm/utils/gn/secondary/libcxx/src/BUILD.gn
index cfd1f5f08b4e..1c52d341ec82 100644
--- a/llvm/utils/gn/secondary/libcxx/src/BUILD.gn
+++ b/llvm/utils/gn/secondary/libcxx/src/BUILD.gn
@@ -95,7 +95,6 @@ config("cxx_config") {
     } else {
       cflags_cc += [ "-fno-exceptions" ]
     }
-    defines += [ "_LIBCPP_NO_EXCEPTIONS" ]
   }
   if (!libcxx_enable_rtti) {
     if (current_os == "win") {


        


More information about the libcxx-commits mailing list