Skip to content

Commit ff4a3ee

Browse files
committed
[libc++] Define a few Lit features using the new DSL
This commit migrates some of the Lit features from config.py to the new DSL. This simplifies config.py and is a first step towards defining all the features using the DSL instead of the complex logic in config.py. Differential Revision: https://reviews.llvm.org/D78382
1 parent 0863e94 commit ff4a3ee

File tree

2 files changed

+37
-69
lines changed

2 files changed

+37
-69
lines changed

libcxx/utils/libcxx/test/config.py

Lines changed: 7 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from libcxx.test.executor import *
2323
from libcxx.test.tracing import *
2424
import libcxx.util
25+
import libcxx.test.features
2526

2627
def loadSiteConfig(lit_config, config, param_name, env_name):
2728
# We haven't loaded the site specific configuration (the user is
@@ -130,7 +131,6 @@ def configure(self):
130131
self.configure_obj_root()
131132
self.configure_cxx_stdlib_under_test()
132133
self.configure_cxx_library_root()
133-
self.configure_use_thread_safety()
134134
self.configure_ccache()
135135
self.configure_compile_flags()
136136
self.configure_link_flags()
@@ -141,11 +141,14 @@ def configure(self):
141141
self.configure_sanitizer()
142142
self.configure_coverage()
143143
self.configure_modules()
144-
self.configure_coroutines()
145-
self.configure_blocks()
146-
self.configure_objc_arc()
147144
self.configure_substitutions()
148145
self.configure_features()
146+
self.configure_new_features()
147+
148+
def configure_new_features(self):
149+
supportedFeatures = [f for f in libcxx.test.features.features if f.isSupported(self.config)]
150+
for feature in supportedFeatures:
151+
feature.enableIn(self.config)
149152

150153
def print_config_info(self):
151154
# Print the final compile and link flags.
@@ -322,14 +325,6 @@ def configure_cxx_stdlib_under_test(self):
322325
if self.get_lit_conf('enable_experimental') is None:
323326
self.config.enable_experimental = 'true'
324327

325-
def configure_use_thread_safety(self):
326-
'''If set, run clang with -verify on failing tests.'''
327-
has_thread_safety = self.cxx.hasCompileFlag('-Werror=thread-safety')
328-
if has_thread_safety:
329-
self.cxx.compile_flags += ['-Werror=thread-safety']
330-
self.config.available_features.add('thread-safety')
331-
self.lit_config.note("enabling thread-safety annotations")
332-
333328
def configure_ccache(self):
334329
use_ccache_default = os.environ.get('LIBCXX_USE_CCACHE') is not None
335330
use_ccache = self.get_lit_bool('use_ccache', use_ccache_default)
@@ -384,36 +379,9 @@ def configure_features(self):
384379
if not self.get_lit_bool('enable_filesystem', default=True):
385380
self.config.available_features.add('c++filesystem-disabled')
386381

387-
388-
# Run a compile test for the -fsized-deallocation flag. This is needed
389-
# in test/std/language.support/support.dynamic/new.delete
390-
if self.cxx.hasCompileFlag('-fsized-deallocation'):
391-
self.config.available_features.add('-fsized-deallocation')
392-
393-
if self.cxx.hasCompileFlag('-faligned-allocation'):
394-
self.config.available_features.add('-faligned-allocation')
395-
396-
if self.cxx.hasCompileFlag('-fdelayed-template-parsing'):
397-
self.config.available_features.add('fdelayed-template-parsing')
398-
399382
if self.get_lit_bool('has_libatomic', False):
400383
self.config.available_features.add('libatomic')
401384

402-
macros = self._dump_macros_verbose()
403-
if '__cpp_if_constexpr' not in macros:
404-
self.config.available_features.add('libcpp-no-if-constexpr')
405-
406-
if '__cpp_structured_bindings' not in macros:
407-
self.config.available_features.add('libcpp-no-structured-bindings')
408-
409-
if '__cpp_deduction_guides' not in macros or \
410-
intMacroValue(macros['__cpp_deduction_guides']) < 201611:
411-
self.config.available_features.add('libcpp-no-deduction-guides')
412-
413-
if '__cpp_concepts' not in macros or \
414-
intMacroValue(macros['__cpp_concepts']) < 201811:
415-
self.config.available_features.add('libcpp-no-concepts')
416-
417385
if self.target_info.is_windows():
418386
self.config.available_features.add('windows')
419387
if self.cxx_stdlib_under_test == 'libc++':
@@ -429,12 +397,6 @@ def configure_features(self):
429397
self.config.available_features.add('libcxx_gdb')
430398
self.cxx.libcxx_gdb = libcxx_gdb
431399

432-
# Support Objective-C++ only on MacOS and if the compiler supports it.
433-
if self.target_info.platform() == "darwin" and \
434-
self.target_info.is_host_macosx() and \
435-
self.cxx.hasCompileFlag(["-x", "objective-c++", "-fobjc-arc"]):
436-
self.config.available_features.add("objective-c++")
437-
438400
def configure_compile_flags(self):
439401
self.configure_default_compile_flags()
440402
# Configure extra flags
@@ -820,9 +782,6 @@ def configure_warnings(self):
820782
# don't enable warnings in system headers on GCC.
821783
if self.cxx.type != 'gcc':
822784
self.cxx.warning_flags += ['-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER']
823-
if self.cxx.hasWarningFlag('-Wuser-defined-warnings'):
824-
self.cxx.warning_flags += ['-Wuser-defined-warnings']
825-
self.config.available_features.add('diagnose-if-support')
826785
self.cxx.addWarningFlagIfSupported('-Wshadow')
827786
self.cxx.addWarningFlagIfSupported('-Wno-unused-command-line-argument')
828787
self.cxx.addWarningFlagIfSupported('-Wno-attributes')
@@ -908,27 +867,6 @@ def configure_coverage(self):
908867
self.cxx.flags += ['-g', '--coverage']
909868
self.cxx.compile_flags += ['-O0']
910869

911-
def configure_coroutines(self):
912-
if self.cxx.hasCompileFlag('-fcoroutines-ts'):
913-
macros = self._dump_macros_verbose(flags=['-fcoroutines-ts'])
914-
if '__cpp_coroutines' not in macros:
915-
self.lit_config.warning('-fcoroutines-ts is supported but '
916-
'__cpp_coroutines is not defined')
917-
# Consider coroutines supported only when the feature test macro
918-
# reflects a recent value.
919-
if intMacroValue(macros['__cpp_coroutines']) >= 201703:
920-
self.config.available_features.add('fcoroutines-ts')
921-
922-
def configure_blocks(self):
923-
if self.cxx.hasCompileFlag('-fblocks'):
924-
self.config.available_features.add('has-fblocks')
925-
926-
def configure_objc_arc(self):
927-
cxx = copy.deepcopy(self.cxx)
928-
cxx.source_lang = 'objective-c++'
929-
if cxx.hasCompileFlag('-fobjc-arc'):
930-
self.config.available_features.add('has-fobjc-arc')
931-
932870
def configure_modules(self):
933871
modules_flags = ['-fmodules']
934872
if not self.target_info.is_darwin():

libcxx/utils/libcxx/test/features.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#===----------------------------------------------------------------------===##
2+
#
3+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
# See https://llvm.org/LICENSE.txt for license information.
5+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
#
7+
#===----------------------------------------------------------------------===##
8+
9+
from libcxx.test.dsl import *
10+
import sys
11+
12+
features = [
13+
Feature(name='fcoroutines-ts', compileFlag='-fcoroutines-ts',
14+
when=lambda cfg: hasCompileFlag(cfg, '-fcoroutines-ts') and
15+
featureTestMacros(cfg, flags='-fcoroutines-ts').get('__cpp_coroutines', 0) >= 201703),
16+
17+
Feature(name='thread-safety', when=lambda cfg: hasCompileFlag(cfg, '-Werror=thread-safety'), compileFlag='-Werror=thread-safety'),
18+
Feature(name='has-fblocks', when=lambda cfg: hasCompileFlag(cfg, '-fblocks')),
19+
Feature(name='-fsized-deallocation', when=lambda cfg: hasCompileFlag(cfg, '-fsized-deallocation')),
20+
Feature(name='-faligned-allocation', when=lambda cfg: hasCompileFlag(cfg, '-faligned-allocation')),
21+
Feature(name='fdelayed-template-parsing', when=lambda cfg: hasCompileFlag(cfg, '-fdelayed-template-parsing')),
22+
Feature(name='libcpp-no-if-constexpr', when=lambda cfg: '__cpp_if_constexpr' not in featureTestMacros(cfg)),
23+
Feature(name='libcpp-no-structured-bindings', when=lambda cfg: '__cpp_structured_bindings' not in featureTestMacros(cfg)),
24+
Feature(name='libcpp-no-deduction-guides', when=lambda cfg: featureTestMacros(cfg).get('__cpp_deduction_guides', 0) < 201611),
25+
Feature(name='libcpp-no-concepts', when=lambda cfg: featureTestMacros(cfg).get('__cpp_concepts', 0) < 201811),
26+
Feature(name='has-fobjc-arc', when=lambda cfg: hasCompileFlag(cfg, '-xobjective-c++ -fobjc-arc') and
27+
sys.platform.lower().strip() == 'darwin'), # TODO: this doesn't handle cross-compiling to Apple platforms.
28+
Feature(name='objective-c++', when=lambda cfg: hasCompileFlag(cfg, '-xobjective-c++ -fobjc-arc')),
29+
Feature(name='diagnose-if-support', when=lambda cfg: hasCompileFlag(cfg, '-Wuser-defined-warnings'), compileFlag='-Wuser-defined-warnings'),
30+
]

0 commit comments

Comments
 (0)