diff --git a/libcxx/test/lit.site.cfg.in b/libcxx/test/lit.site.cfg.in --- a/libcxx/test/lit.site.cfg.in +++ b/libcxx/test/lit.site.cfg.in @@ -4,10 +4,8 @@ config.libcxx_src_root = "@LIBCXX_SOURCE_DIR@" config.libcxx_obj_root = "@LIBCXX_BINARY_DIR@" config.cxx_library_root = "@LIBCXX_LIBRARY_DIR@" -config.enable_exceptions = @LIBCXX_ENABLE_EXCEPTIONS@ config.enable_experimental = @LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY@ config.enable_filesystem = @LIBCXX_ENABLE_FILESYSTEM@ -config.enable_rtti = @LIBCXX_ENABLE_RTTI@ config.enable_shared = @LIBCXX_LINK_TESTS_WITH_SHARED_LIBCXX@ config.enable_32bit = @LIBCXX_BUILD_32_BITS@ config.cxx_abi = "@LIBCXX_CXX_ABI_LIBNAME@" @@ -37,6 +35,9 @@ config.pstl_obj_root = "@ParallelSTL_BINARY_DIR@" if @LIBCXX_ENABLE_PARALLEL_ALGORITHMS@ else None config.libcxx_gdb = "@LIBCXX_GDB@" +lit_config.params['enable_exceptions'] = "@LIBCXX_ENABLE_EXCEPTIONS@" +lit_config.params['enable_rtti'] = "@LIBCXX_ENABLE_RTTI@" + # Code signing config.llvm_codesign_identity = "@LLVM_CODESIGNING_IDENTITY@" diff --git a/libcxx/utils/libcxx/test/config.py b/libcxx/utils/libcxx/test/config.py --- a/libcxx/utils/libcxx/test/config.py +++ b/libcxx/utils/libcxx/test/config.py @@ -22,6 +22,8 @@ from libcxx.test.executor import * from libcxx.test.tracing import * import libcxx.util +import libcxx.test.features +import libcxx.test.params def loadSiteConfig(lit_config, config, param_name, env_name): # We haven't loaded the site specific configuration (the user is @@ -131,7 +133,6 @@ self.configure_cxx_stdlib_under_test() self.configure_cxx_library_root() self.configure_use_clang_verify() - self.configure_use_thread_safety() self.configure_ccache() self.configure_compile_flags() self.configure_link_flags() @@ -142,11 +143,21 @@ self.configure_sanitizer() self.configure_coverage() self.configure_modules() - self.configure_coroutines() - self.configure_blocks() - self.configure_objc_arc() self.configure_substitutions() self.configure_features() + self.configure_new_params() + self.configure_new_features() + + def configure_new_params(self): + for param in libcxx.test.params.parameters: + feature = param.getFeature(self.config, self.lit_config.params) + if feature: + feature.enableIn(self.config) + + def configure_new_features(self): + supportedFeatures = [f for f in libcxx.test.features.features if f.isSupported(self.config)] + for feature in supportedFeatures: + feature.enableIn(self.config) def print_config_info(self): # Print the final compile and link flags. @@ -333,14 +344,6 @@ self.lit_config.note( "inferred use_clang_verify as: %r" % self.use_clang_verify) - def configure_use_thread_safety(self): - '''If set, run clang with -verify on failing tests.''' - has_thread_safety = self.cxx.hasCompileFlag('-Werror=thread-safety') - if has_thread_safety: - self.cxx.compile_flags += ['-Werror=thread-safety'] - self.config.available_features.add('thread-safety') - self.lit_config.note("enabling thread-safety annotations") - def configure_ccache(self): use_ccache_default = os.environ.get('LIBCXX_USE_CCACHE') is not None use_ccache = self.get_lit_bool('use_ccache', use_ccache_default) @@ -395,36 +398,9 @@ if not self.get_lit_bool('enable_filesystem', default=True): self.config.available_features.add('c++filesystem-disabled') - - # Run a compile test for the -fsized-deallocation flag. This is needed - # in test/std/language.support/support.dynamic/new.delete - if self.cxx.hasCompileFlag('-fsized-deallocation'): - self.config.available_features.add('-fsized-deallocation') - - if self.cxx.hasCompileFlag('-faligned-allocation'): - self.config.available_features.add('-faligned-allocation') - - if self.cxx.hasCompileFlag('-fdelayed-template-parsing'): - self.config.available_features.add('fdelayed-template-parsing') - if self.get_lit_bool('has_libatomic', False): self.config.available_features.add('libatomic') - macros = self._dump_macros_verbose() - if '__cpp_if_constexpr' not in macros: - self.config.available_features.add('libcpp-no-if-constexpr') - - if '__cpp_structured_bindings' not in macros: - self.config.available_features.add('libcpp-no-structured-bindings') - - if '__cpp_deduction_guides' not in macros or \ - intMacroValue(macros['__cpp_deduction_guides']) < 201611: - self.config.available_features.add('libcpp-no-deduction-guides') - - if '__cpp_concepts' not in macros or \ - intMacroValue(macros['__cpp_concepts']) < 201811: - self.config.available_features.add('libcpp-no-concepts') - if self.target_info.is_windows(): self.config.available_features.add('windows') if self.cxx_stdlib_under_test == 'libc++': @@ -440,12 +416,6 @@ self.config.available_features.add('libcxx_gdb') self.cxx.libcxx_gdb = libcxx_gdb - # Support Objective-C++ only on MacOS and if the compiler supports it. - if self.target_info.platform() == "darwin" and \ - self.target_info.is_host_macosx() and \ - self.cxx.hasCompileFlag(["-x", "objective-c++", "-fobjc-arc"]): - self.config.available_features.add("objective-c++") - def configure_compile_flags(self): self.configure_default_compile_flags() # Configure extra flags @@ -499,8 +469,6 @@ self.configure_compile_flags_header_includes() self.target_info.add_cxx_compile_flags(self.cxx.compile_flags) # Configure feature flags. - self.configure_compile_flags_exceptions() - self.configure_compile_flags_rtti() self.configure_compile_flags_abi_version() enable_32bit = self.get_lit_bool('enable_32bit', False) if enable_32bit: @@ -645,20 +613,6 @@ self.config.available_features.add(m.lower()[1:].replace('_', '-')) return feature_macros - - - def configure_compile_flags_exceptions(self): - enable_exceptions = self.get_lit_bool('enable_exceptions', True) - if not enable_exceptions: - self.config.available_features.add('no-exceptions') - self.cxx.compile_flags += ['-fno-exceptions'] - - def configure_compile_flags_rtti(self): - 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'] - def configure_compile_flags_abi_version(self): abi_version = self.get_lit_conf('abi_version', '').strip() abi_unstable = self.get_lit_bool('abi_unstable') @@ -833,9 +787,6 @@ # don't enable warnings in system headers on GCC. if self.cxx.type != 'gcc': self.cxx.warning_flags += ['-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER'] - if self.cxx.hasWarningFlag('-Wuser-defined-warnings'): - self.cxx.warning_flags += ['-Wuser-defined-warnings'] - self.config.available_features.add('diagnose-if-support') self.cxx.addWarningFlagIfSupported('-Wshadow') self.cxx.addWarningFlagIfSupported('-Wno-unused-command-line-argument') self.cxx.addWarningFlagIfSupported('-Wno-attributes') @@ -921,27 +872,6 @@ self.cxx.flags += ['-g', '--coverage'] self.cxx.compile_flags += ['-O0'] - def configure_coroutines(self): - if self.cxx.hasCompileFlag('-fcoroutines-ts'): - macros = self._dump_macros_verbose(flags=['-fcoroutines-ts']) - if '__cpp_coroutines' not in macros: - self.lit_config.warning('-fcoroutines-ts is supported but ' - '__cpp_coroutines is not defined') - # Consider coroutines supported only when the feature test macro - # reflects a recent value. - if intMacroValue(macros['__cpp_coroutines']) >= 201703: - self.config.available_features.add('fcoroutines-ts') - - def configure_blocks(self): - if self.cxx.hasCompileFlag('-fblocks'): - self.config.available_features.add('has-fblocks') - - def configure_objc_arc(self): - cxx = copy.deepcopy(self.cxx) - cxx.source_lang = 'objective-c++' - if cxx.hasCompileFlag('-fobjc-arc'): - self.config.available_features.add('has-fobjc-arc') - def configure_modules(self): modules_flags = ['-fmodules'] if not self.target_info.is_darwin(): diff --git a/libcxx/utils/libcxx/test/features.py b/libcxx/utils/libcxx/test/features.py new file mode 100644 --- /dev/null +++ b/libcxx/utils/libcxx/test/features.py @@ -0,0 +1,28 @@ +#===----------------------------------------------------------------------===## +# +# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +# +#===----------------------------------------------------------------------===## + +from libcxx.test.dsl import * + +features = [ + Feature(name='fcoroutines-ts', compileFlag='-fcoroutines-ts', + when=lambda cfg: hasCompileFlag(cfg, '-fcoroutines-ts') and + featureTestMacros(cfg, flags='-fcoroutines-ts').get('__cpp_coroutines', 0) >= 201703), + + Feature(name='thread-safety', when=lambda cfg: hasCompileFlag(cfg, '-Werror=thread-safety'), compileFlag='-Werror=thread-safety'), + Feature(name='has-fblocks', when=lambda cfg: hasCompileFlag(cfg, '-fblocks')), + Feature(name='-fsized-deallocation', when=lambda cfg: hasCompileFlag(cfg, '-fsized-deallocation')), + Feature(name='-faligned-allocation', when=lambda cfg: hasCompileFlag(cfg, '-faligned-allocation')), + Feature(name='fdelayed-template-parsing', when=lambda cfg: hasCompileFlag(cfg, '-fdelayed-template-parsing')), + Feature(name='libcpp-no-if-constexpr', when=lambda cfg: '__cpp_if_constexpr' not in featureTestMacros(cfg)), + Feature(name='libcpp-no-structured-bindings', when=lambda cfg: '__cpp_structured_bindings' not in featureTestMacros(cfg)), + Feature(name='libcpp-no-deduction-guides', when=lambda cfg: featureTestMacros(cfg).get('__cpp_deduction_guides', 0) < 201611), + Feature(name='libcpp-no-concepts', when=lambda cfg: featureTestMacros(cfg).get('__cpp_concepts', 0) < 201811), + Feature(name='has-fobjc-arc', when=lambda cfg: hasCompileFlag(cfg, '-xobjective-c++ -fobjc-arc')), + Feature(name='objective-c++', when=lambda cfg: hasCompileFlag(cfg, '-xobjective-c++ -fobjc-arc')), + Feature(name='diagnose-if-support', when=lambda cfg: hasCompileFlag(cfg, '-Wuser-defined-warnings'), compileFlag='-Wuser-defined-warnings'), +] diff --git a/libcxx/utils/libcxx/test/params.py b/libcxx/utils/libcxx/test/params.py new file mode 100644 --- /dev/null +++ b/libcxx/utils/libcxx/test/params.py @@ -0,0 +1,23 @@ +#===----------------------------------------------------------------------===## +# +# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +# +#===----------------------------------------------------------------------===## + +from libcxx.test.dsl import * + +parameters = [ + Parameter(name='enable_exceptions', choices=[True, False], type=bool, default=True, + help="Whether to enable exceptions when compiling the test suite.", + feature=lambda exceptions: None if exceptions else + Feature(name='no-exceptions', compileFlag='-fno-exceptions', + when=lambda cfg: hasCompileFlag(cfg, '-fno-exceptions'))), + + Parameter(name='enable_rtti', choices=[True, False], type=bool, default=True, + help="Whether to enable RTTI when compiling the test suite.", + feature=lambda rtti: None if rtti else + Feature(name='no-rtti', compileFlag='-fno-rtti -D_LIBCPP_NO_RTTI', + when=lambda cfg: hasCompileFlag(cfg, '-fno-rtti'))), +] diff --git a/libcxxabi/test/lit.site.cfg.in b/libcxxabi/test/lit.site.cfg.in --- a/libcxxabi/test/lit.site.cfg.in +++ b/libcxxabi/test/lit.site.cfg.in @@ -18,7 +18,6 @@ config.executor = "@LIBCXXABI_EXECUTOR@" config.libcxxabi_shared = @LIBCXXABI_LINK_TESTS_WITH_SHARED_LIBCXXABI@ config.enable_shared = @LIBCXXABI_LINK_TESTS_WITH_SHARED_LIBCXX@ -config.enable_exceptions = @LIBCXXABI_ENABLE_EXCEPTIONS@ config.host_triple = "@LLVM_HOST_TRIPLE@" config.target_triple = "@TARGET_TRIPLE@" config.use_target = bool("@LIBCXXABI_TARGET_TRIPLE@") @@ -29,5 +28,7 @@ config.pstl_src_root = "@ParallelSTL_SOURCE_DIR@" if @LIBCXX_ENABLE_PARALLEL_ALGORITHMS@ else None config.pstl_obj_root = "@ParallelSTL_BINARY_DIR@" if @LIBCXX_ENABLE_PARALLEL_ALGORITHMS@ else None +lit_config.params['enable_exceptions'] = "@LIBCXXABI_ENABLE_EXCEPTIONS@" + # Let the main config do the real work. lit_config.load_config(config, "@LIBCXXABI_SOURCE_DIR@/test/lit.cfg") diff --git a/libunwind/test/lit.cfg b/libunwind/test/lit.cfg --- a/libunwind/test/lit.cfg +++ b/libunwind/test/lit.cfg @@ -24,7 +24,7 @@ config.test_source_root = os.path.dirname(__file__) # needed to test libunwind with code that throws exceptions -config.enable_exceptions = True +lit_config.params['enable_exceptions'] = True # Infer the libcxx_test_source_root for configuration import. # If libcxx_source_root isn't specified in the config, assume that the libcxx diff --git a/libunwind/test/lit.site.cfg.in b/libunwind/test/lit.site.cfg.in --- a/libunwind/test/lit.site.cfg.in +++ b/libunwind/test/lit.site.cfg.in @@ -18,7 +18,6 @@ config.executor = "@LIBUNWIND_EXECUTOR@" config.libunwind_shared = @LIBUNWIND_ENABLE_SHARED@ config.enable_shared = @LIBCXX_ENABLE_SHARED@ -config.enable_exceptions = @LIBUNWIND_ENABLE_EXCEPTIONS@ config.arm_ehabi = @LIBUNWIND_USES_ARM_EHABI@ config.host_triple = "@LLVM_HOST_TRIPLE@" config.target_triple = "@TARGET_TRIPLE@" @@ -27,5 +26,7 @@ config.gcc_toolchain = "@LIBUNWIND_GCC_TOOLCHAIN@" config.cxx_ext_threads = @LIBUNWIND_BUILD_EXTERNAL_THREAD_LIBRARY@ +lit_config.params['enable_exceptions'] = "@LIBUNWIND_ENABLE_EXCEPTIONS@" + # Let the main config do the real work. lit_config.load_config(config, "@LIBUNWIND_SOURCE_DIR@/test/lit.cfg")