From c2279b262fe3b5ba9e9ab931884d290fa09bbf5c Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Tue, 20 Oct 2020 15:52:57 -0400 Subject: [PATCH] [libc++] Make it easier to add new restrictions for feature-test macro tests --- .../generate_feature_test_macro_components.py | 24 ++++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/libcxx/utils/generate_feature_test_macro_components.py b/libcxx/utils/generate_feature_test_macro_components.py index edf6689..be4bfe4 100755 --- a/libcxx/utils/generate_feature_test_macro_components.py +++ b/libcxx/utils/generate_feature_test_macro_components.py @@ -483,6 +483,18 @@ feature_test_macros = sorted([ add_version_header(x) for x in [ }, ]], key=lambda tc: tc["name"]) +# Map from each header to the Lit annotations that should be used for +# tests that include that header. +# +# For example, when threads are not supported, any feature-test-macro test +# that includes should be marked as UNSUPPORTED, because including +# is a hard error in that case. +lit_markup = { + "atomic": ["UNSUPPORTED: libcpp-has-no-threads"], + "shared_mutex": ["UNSUPPORTED: libcpp-has-no-threads"], + "thread": ["UNSUPPORTED: libcpp-has-no-threads"], +} + def get_std_dialects(): std_dialects = ['c++14', 'c++17', 'c++2a'] return list(std_dialects) @@ -734,10 +746,6 @@ def generate_synopsis(test_list): result += "*/" return result -def is_threading_header_unsafe_to_include(h): - # NOTE: "" does not blow up when included without threads. - return h in ['atomic', 'shared_mutex'] - def produce_tests(): headers = set([h for tc in feature_test_macros for h in tc["headers"]]) for h in headers: @@ -746,9 +754,7 @@ def produce_tests(): for tc in test_list: assert 'unimplemented' in tc.keys() continue - test_tags = "" - if is_threading_header_unsafe_to_include(h): - test_tags += '\n// UNSUPPORTED: libcpp-has-no-threads\n' + markup = '\n'.join('// ' + tag for tag in lit_markup.get(h, [])) test_body = \ """//===----------------------------------------------------------------------===// // @@ -760,7 +766,7 @@ def produce_tests(): // // WARNING: This test was generated by {script_name} // and should not be edited manually. -{test_tags} +{markup} // <{header}> // Test the feature test macros defined by <{header}> @@ -791,7 +797,7 @@ def produce_tests(): int main(int, char**) {{ return 0; }} """.format(script_name=script_name, header=h, - test_tags=test_tags, + markup=('\n{}\n'.format(markup) if markup else ''), synopsis=generate_synopsis(test_list), cxx11_tests=generate_std_test(test_list, 'c++11').strip(), cxx14_tests=generate_std_test(test_list, 'c++14').strip(), -- 2.7.4