[libc++/libc++abi] Automatically detect whether exceptions are enabled
authorLouis Dionne <ldionne@apple.com>
Fri, 3 Jul 2020 17:46:41 +0000 (13:46 -0400)
committerLouis Dionne <ldionne@apple.com>
Fri, 3 Jul 2020 18:58:09 +0000 (14:58 -0400)
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.

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

index 9fb4e40..d215ef6 100644 (file)
@@ -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()
index a0de82c..7e4c374 100644 (file)
@@ -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
index 787b86a..78f8429 100644 (file)
@@ -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>
index c577036..b6f1f08 100644 (file)
@@ -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-)
index cbbb1c1..b5444d6 100644 (file)
 #  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
index cfd1f5f..1c52d34 100644 (file)
@@ -95,7 +95,6 @@ config("cxx_config") {
     } else {
       cflags_cc += [ "-fno-exceptions" ]
     }
-    defines += [ "_LIBCPP_NO_EXCEPTIONS" ]
   }
   if (!libcxx_enable_rtti) {
     if (current_os == "win") {