From: Louis Dionne Date: Fri, 3 Jul 2020 17:46:41 +0000 (-0400) Subject: [libc++/libc++abi] Automatically detect whether exceptions are enabled X-Git-Tag: llvmorg-12-init~1074 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=71d88cebfb42c8c5ac2d54b42afdcca956e55660;p=platform%2Fupstream%2Fllvm.git [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. --- diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt index 9fb4e40..d215ef6 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 a0de82c..7e4c3743 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 787b86a..78f8429 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 #include diff --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt index c577036..b6f1f08 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 cbbb1c1..b5444d6 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 cfd1f5f..1c52d34 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") {