[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.
This commit is contained in:
Louis Dionne 2020-07-03 13:46:41 -04:00
parent 35808ab8e1
commit 71d88cebfb
6 changed files with 13 additions and 8 deletions

View 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()

View 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

View 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>

View 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-)

View File

@ -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

View 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") {