[libcxx-commits] [libcxx] c2279b2 - [libc++] Make it easier to add new restrictions for feature-test macro tests

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Oct 20 12:53:44 PDT 2020


Author: Louis Dionne
Date: 2020-10-20T15:52:57-04:00
New Revision: c2279b262fe3b5ba9e9ab931884d290fa09bbf5c

URL: https://github.com/llvm/llvm-project/commit/c2279b262fe3b5ba9e9ab931884d290fa09bbf5c
DIFF: https://github.com/llvm/llvm-project/commit/c2279b262fe3b5ba9e9ab931884d290fa09bbf5c.diff

LOG: [libc++] Make it easier to add new restrictions for feature-test macro tests

Added: 
    

Modified: 
    libcxx/utils/generate_feature_test_macro_components.py

Removed: 
    


################################################################################
diff  --git a/libcxx/utils/generate_feature_test_macro_components.py b/libcxx/utils/generate_feature_test_macro_components.py
index edf668921f9c..be4bfe475667 100755
--- a/libcxx/utils/generate_feature_test_macro_components.py
+++ b/libcxx/utils/generate_feature_test_macro_components.py
@@ -483,6 +483,18 @@ def add_version_header(tc):
    },
 ]], 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 <thread> should be marked as UNSUPPORTED, because including
+# <thread> 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 mk_line(prefix, suffix):
     result += "*/"
     return result
 
-def is_threading_header_unsafe_to_include(h):
-  # NOTE: "<mutex>" 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(),


        


More information about the libcxx-commits mailing list