From eaca1e4e54905815b444e1234096c70adc9812f6 Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Tue, 14 Jul 2020 16:28:41 -0400 Subject: [PATCH] [libc++] Automatically detect whether RTTI is enabled Instead of detecting it automatically but also allowing for the setting to be specified explicitly, always detect whether exceptions are enabled based on whether -fno-rtti (or equivalent) is used. It's less confusing to have a single way of tweaking that knob. This change follows the lead of 71d88cebfb42. --- libcxx/CMakeLists.txt | 1 - libcxx/include/__config | 17 ++++++----------- libcxx/utils/libcxx/test/config.py | 2 +- llvm/utils/gn/secondary/libcxx/src/BUILD.gn | 1 - 4 files changed, 7 insertions(+), 14 deletions(-) diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt index 88dc4553069e..aabe31fa6ec1 100644 --- a/libcxx/CMakeLists.txt +++ b/libcxx/CMakeLists.txt @@ -639,7 +639,6 @@ endfunction() # RTTI flags ================================================================== function(cxx_add_rtti_flags target) if (NOT LIBCXX_ENABLE_RTTI) - target_compile_definitions(${target} PUBLIC -D_LIBCPP_NO_RTTI) target_add_compile_flags_if_supported(${target} PUBLIC -GR-) target_add_compile_flags_if_supported(${target} PUBLIC -fno-rtti) endif() diff --git a/libcxx/include/__config b/libcxx/include/__config index 7e4c37431ea4..575147cead42 100644 --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -423,10 +423,6 @@ typedef __char32_t char32_t; # define _LIBCPP_NO_EXCEPTIONS #endif -#if !(__has_feature(cxx_rtti)) && !defined(_LIBCPP_NO_RTTI) -#define _LIBCPP_NO_RTTI -#endif - #if !(__has_feature(cxx_strong_enums)) #define _LIBCPP_HAS_NO_STRONG_ENUMS #endif @@ -1109,13 +1105,12 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container( #endif // Try to find out if RTTI is disabled. -// g++ and cl.exe have RTTI on by default and define a macro when it is. -#if !defined(_LIBCPP_NO_RTTI) -# if defined(__GNUC__) && !defined(__GXX_RTTI) -# define _LIBCPP_NO_RTTI -# elif defined(_LIBCPP_COMPILER_MSVC) && !defined(_CPPRTTI) -# define _LIBCPP_NO_RTTI -# endif +#if defined(_LIBCPP_COMPILER_CLANG) && !__has_feature(cxx_rtti) +# define _LIBCPP_NO_RTTI +#elif defined(__GNUC__) && !defined(__GXX_RTTI) +# define _LIBCPP_NO_RTTI +#elif defined(_LIBCPP_COMPILER_MSVC) && !defined(_CPPRTTI) +# define _LIBCPP_NO_RTTI #endif #ifndef _LIBCPP_WEAK diff --git a/libcxx/utils/libcxx/test/config.py b/libcxx/utils/libcxx/test/config.py index 99a966dbfdfd..b88b085d408f 100644 --- a/libcxx/utils/libcxx/test/config.py +++ b/libcxx/utils/libcxx/test/config.py @@ -410,7 +410,7 @@ class Configuration(object): enable_rtti = self.get_lit_bool('enable_rtti', True) if not enable_rtti: self.config.available_features.add('-fno-rtti') - self.cxx.compile_flags += ['-fno-rtti', '-D_LIBCPP_NO_RTTI'] + self.cxx.compile_flags += ['-fno-rtti'] def configure_link_flags(self): # Configure library path diff --git a/llvm/utils/gn/secondary/libcxx/src/BUILD.gn b/llvm/utils/gn/secondary/libcxx/src/BUILD.gn index 1c52d341ec82..09d850036ad1 100644 --- a/llvm/utils/gn/secondary/libcxx/src/BUILD.gn +++ b/llvm/utils/gn/secondary/libcxx/src/BUILD.gn @@ -102,7 +102,6 @@ config("cxx_config") { } else { cflags_cc += [ "-fno-rtti" ] } - defines += [ "_LIBCPP_NO_RTTI" ] } } -- 2.34.1