[libc++] Automatically detect whether RTTI is enabled
authorLouis Dionne <ldionne@apple.com>
Tue, 14 Jul 2020 20:28:41 +0000 (16:28 -0400)
committerLouis Dionne <ldionne@apple.com>
Tue, 14 Jul 2020 20:51:37 +0000 (16:51 -0400)
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
libcxx/include/__config
libcxx/utils/libcxx/test/config.py
llvm/utils/gn/secondary/libcxx/src/BUILD.gn

index 88dc4553069e03210692fe47071bd192fb072339..aabe31fa6ec18afc697c6d5d215a5d0a1c11aecd 100644 (file)
@@ -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()
index 7e4c37431ea44ae1fbe745767d71b3762058ee62..575147cead42d9e291b33801990a7893dfff3196 100644 (file)
@@ -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
index 99a966dbfdfde3bd982740c8cde8258ac8552913..b88b085d408f97e1fc3c4c33dec5b31554b66f26 100644 (file)
@@ -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
index 1c52d341ec8222aedf92a800287f10aec1f4b453..09d850036ad1b62ec5114a56cf9333a237314e4a 100644 (file)
@@ -102,7 +102,6 @@ config("cxx_config") {
     } else {
       cflags_cc += [ "-fno-rtti" ]
     }
-    defines += [ "_LIBCPP_NO_RTTI" ]
   }
 }