From 05019eb79f9e15fc6e48acdd634c103239357824 Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Wed, 16 Jan 2019 02:10:28 +0000 Subject: [PATCH] Fix feature test macros for atomics/mutexes without threading llvm-svn: 351291 --- libcxx/include/version | 16 ++- .../support.limits.general/atomic.version.pass.cpp | 34 +++++-- .../generate_feature_test_macro_components.py | 22 +++- .../shared_mutex.version.pass.cpp | 82 ++++++++++----- .../version.version.pass.cpp | 112 ++++++++++++++------- 5 files changed, 189 insertions(+), 77 deletions(-) diff --git a/libcxx/include/version b/libcxx/include/version index d37aba1..e37afc4 100644 --- a/libcxx/include/version +++ b/libcxx/include/version @@ -135,7 +135,9 @@ __cpp_lib_void_t 201411L # define __cpp_lib_quoted_string_io 201304L # define __cpp_lib_result_of_sfinae 201210L # define __cpp_lib_robust_nonmodifying_seq_ops 201304L -# define __cpp_lib_shared_timed_mutex 201402L +# if !defined(_LIBCPP_HAS_NO_THREADS) +# define __cpp_lib_shared_timed_mutex 201402L +# endif # define __cpp_lib_string_udls 201304L # define __cpp_lib_transformation_trait_aliases 201304L # define __cpp_lib_transparent_operators 201210L @@ -152,7 +154,9 @@ __cpp_lib_void_t 201411L # define __cpp_lib_apply 201603L # define __cpp_lib_array_constexpr 201603L # define __cpp_lib_as_const 201510L -# define __cpp_lib_atomic_is_always_lock_free 201603L +# if !defined(_LIBCPP_HAS_NO_THREADS) +# define __cpp_lib_atomic_is_always_lock_free 201603L +# endif # define __cpp_lib_bool_constant 201505L // # define __cpp_lib_boyer_moore_searcher 201603L # define __cpp_lib_byte 201603L @@ -188,7 +192,9 @@ __cpp_lib_void_t 201411L # define __cpp_lib_raw_memory_algorithms 201606L # define __cpp_lib_sample 201603L # define __cpp_lib_scoped_lock 201703L -# define __cpp_lib_shared_mutex 201505L +# if !defined(_LIBCPP_HAS_NO_THREADS) +# define __cpp_lib_shared_mutex 201505L +# endif // # define __cpp_lib_shared_ptr_arrays 201611L # define __cpp_lib_shared_ptr_weak_type 201606L # define __cpp_lib_string_view 201606L @@ -203,7 +209,9 @@ __cpp_lib_void_t 201411L #endif #if _LIBCPP_STD_VER > 17 -// # define __cpp_lib_atomic_ref 201806L +# if !defined(_LIBCPP_HAS_NO_THREADS) +// # define __cpp_lib_atomic_ref 201806L +# endif // # define __cpp_lib_bind_front 201811L // # define __cpp_lib_bit_cast 201806L # if !defined(_LIBCPP_NO_HAS_CHAR8_T) diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/atomic.version.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/atomic.version.pass.cpp index 4c0b351..4ba3754 100644 --- a/libcxx/test/std/language.support/support.limits/support.limits.general/atomic.version.pass.cpp +++ b/libcxx/test/std/language.support/support.limits/support.limits.general/atomic.version.pass.cpp @@ -10,6 +10,8 @@ // WARNING: This test was generated by generate_feature_test_macros_tests.py and // should not be edited manually. +// UNSUPPORTED: libcpp-has-no-threads + // // Test the feature test macros defined by @@ -53,11 +55,17 @@ #elif TEST_STD_VER == 17 -# ifndef __cpp_lib_atomic_is_always_lock_free -# error "__cpp_lib_atomic_is_always_lock_free should be defined in c++17" -# endif -# if __cpp_lib_atomic_is_always_lock_free != 201603L -# error "__cpp_lib_atomic_is_always_lock_free should have the value 201603L in c++17" +# if !defined(_LIBCPP_HAS_NO_THREADS) +# ifndef __cpp_lib_atomic_is_always_lock_free +# error "__cpp_lib_atomic_is_always_lock_free should be defined in c++17" +# endif +# if __cpp_lib_atomic_is_always_lock_free != 201603L +# error "__cpp_lib_atomic_is_always_lock_free should have the value 201603L in c++17" +# endif +# else +# ifdef __cpp_lib_atomic_is_always_lock_free +# error "__cpp_lib_atomic_is_always_lock_free should not be defined when !defined(_LIBCPP_HAS_NO_THREADS) is not defined!" +# endif # endif # ifdef __cpp_lib_atomic_ref @@ -70,11 +78,17 @@ #elif TEST_STD_VER > 17 -# ifndef __cpp_lib_atomic_is_always_lock_free -# error "__cpp_lib_atomic_is_always_lock_free should be defined in c++2a" -# endif -# if __cpp_lib_atomic_is_always_lock_free != 201603L -# error "__cpp_lib_atomic_is_always_lock_free should have the value 201603L in c++2a" +# if !defined(_LIBCPP_HAS_NO_THREADS) +# ifndef __cpp_lib_atomic_is_always_lock_free +# error "__cpp_lib_atomic_is_always_lock_free should be defined in c++2a" +# endif +# if __cpp_lib_atomic_is_always_lock_free != 201603L +# error "__cpp_lib_atomic_is_always_lock_free should have the value 201603L in c++2a" +# endif +# else +# ifdef __cpp_lib_atomic_is_always_lock_free +# error "__cpp_lib_atomic_is_always_lock_free should not be defined when !defined(_LIBCPP_HAS_NO_THREADS) is not defined!" +# endif # endif # if !defined(_LIBCPP_VERSION) diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/generate_feature_test_macro_components.py b/libcxx/test/std/language.support/support.limits/support.limits.general/generate_feature_test_macro_components.py index d51df45..2f13ed0 100755 --- a/libcxx/test/std/language.support/support.limits/support.limits.general/generate_feature_test_macro_components.py +++ b/libcxx/test/std/language.support/support.limits/support.limits.general/generate_feature_test_macro_components.py @@ -148,14 +148,18 @@ feature_test_macros = sorted([ add_version_header(x) for x in [ "values": { "c++14": 201402L, }, - "headers": ["shared_mutex"] + "headers": ["shared_mutex"], + "depends": "!defined(_LIBCPP_HAS_NO_THREADS)", + "internal_depends": "!defined(_LIBCPP_HAS_NO_THREADS)", }, # C++17 macros {"name": "__cpp_lib_atomic_is_always_lock_free", "values": { "c++17": 201603L, }, - "headers": ["atomic"] + "headers": ["atomic"], + "depends": "!defined(_LIBCPP_HAS_NO_THREADS)", + "internal_depends": "!defined(_LIBCPP_HAS_NO_THREADS)", }, {"name": "__cpp_lib_filesystem", "values": { @@ -446,6 +450,8 @@ feature_test_macros = sorted([ add_version_header(x) for x in [ "c++17": 201505L, }, "headers": ["shared_mutex"], + "depends": "!defined(_LIBCPP_HAS_NO_THREADS)", + "internal_depends": "!defined(_LIBCPP_HAS_NO_THREADS)", }, {"name": "__cpp_lib_scoped_lock", "values": { @@ -553,6 +559,8 @@ feature_test_macros = sorted([ add_version_header(x) for x in [ }, "headers": ["atomic"], "unimplemented": True, + "depends": "!defined(_LIBCPP_HAS_NO_THREADS)", + "internal_depends": "!defined(_LIBCPP_HAS_NO_THREADS)", }, ]], key=lambda tc: tc["name"]) @@ -802,6 +810,10 @@ 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: @@ -810,6 +822,9 @@ 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' test_body = \ """//===----------------------------------------------------------------------===// // @@ -822,7 +837,7 @@ def produce_tests(): // // WARNING: This test was generated by generate_feature_test_macros_tests.py and // should not be edited manually. - +{test_tags} // <{header}> // Test the feature test macros defined by <{header}> @@ -852,6 +867,7 @@ def produce_tests(): int main() {{}} """.format(header=h, + test_tags=test_tags, 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(), diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/shared_mutex.version.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/shared_mutex.version.pass.cpp index a86aebe..98bdf70 100644 --- a/libcxx/test/std/language.support/support.limits/support.limits.general/shared_mutex.version.pass.cpp +++ b/libcxx/test/std/language.support/support.limits/support.limits.general/shared_mutex.version.pass.cpp @@ -10,6 +10,8 @@ // WARNING: This test was generated by generate_feature_test_macros_tests.py and // should not be edited manually. +// UNSUPPORTED: libcpp-has-no-threads + // // Test the feature test macros defined by @@ -38,43 +40,73 @@ # error "__cpp_lib_shared_mutex should not be defined before c++17" # endif -# ifndef __cpp_lib_shared_timed_mutex -# error "__cpp_lib_shared_timed_mutex should be defined in c++14" -# endif -# if __cpp_lib_shared_timed_mutex != 201402L -# error "__cpp_lib_shared_timed_mutex should have the value 201402L in c++14" +# if !defined(_LIBCPP_HAS_NO_THREADS) +# ifndef __cpp_lib_shared_timed_mutex +# error "__cpp_lib_shared_timed_mutex should be defined in c++14" +# endif +# if __cpp_lib_shared_timed_mutex != 201402L +# error "__cpp_lib_shared_timed_mutex should have the value 201402L in c++14" +# endif +# else +# ifdef __cpp_lib_shared_timed_mutex +# error "__cpp_lib_shared_timed_mutex should not be defined when !defined(_LIBCPP_HAS_NO_THREADS) is not defined!" +# endif # endif #elif TEST_STD_VER == 17 -# ifndef __cpp_lib_shared_mutex -# error "__cpp_lib_shared_mutex should be defined in c++17" -# endif -# if __cpp_lib_shared_mutex != 201505L -# error "__cpp_lib_shared_mutex should have the value 201505L in c++17" +# if !defined(_LIBCPP_HAS_NO_THREADS) +# ifndef __cpp_lib_shared_mutex +# error "__cpp_lib_shared_mutex should be defined in c++17" +# endif +# if __cpp_lib_shared_mutex != 201505L +# error "__cpp_lib_shared_mutex should have the value 201505L in c++17" +# endif +# else +# ifdef __cpp_lib_shared_mutex +# error "__cpp_lib_shared_mutex should not be defined when !defined(_LIBCPP_HAS_NO_THREADS) is not defined!" +# endif # endif -# ifndef __cpp_lib_shared_timed_mutex -# error "__cpp_lib_shared_timed_mutex should be defined in c++17" -# endif -# if __cpp_lib_shared_timed_mutex != 201402L -# error "__cpp_lib_shared_timed_mutex should have the value 201402L in c++17" +# if !defined(_LIBCPP_HAS_NO_THREADS) +# ifndef __cpp_lib_shared_timed_mutex +# error "__cpp_lib_shared_timed_mutex should be defined in c++17" +# endif +# if __cpp_lib_shared_timed_mutex != 201402L +# error "__cpp_lib_shared_timed_mutex should have the value 201402L in c++17" +# endif +# else +# ifdef __cpp_lib_shared_timed_mutex +# error "__cpp_lib_shared_timed_mutex should not be defined when !defined(_LIBCPP_HAS_NO_THREADS) is not defined!" +# endif # endif #elif TEST_STD_VER > 17 -# ifndef __cpp_lib_shared_mutex -# error "__cpp_lib_shared_mutex should be defined in c++2a" -# endif -# if __cpp_lib_shared_mutex != 201505L -# error "__cpp_lib_shared_mutex should have the value 201505L in c++2a" +# if !defined(_LIBCPP_HAS_NO_THREADS) +# ifndef __cpp_lib_shared_mutex +# error "__cpp_lib_shared_mutex should be defined in c++2a" +# endif +# if __cpp_lib_shared_mutex != 201505L +# error "__cpp_lib_shared_mutex should have the value 201505L in c++2a" +# endif +# else +# ifdef __cpp_lib_shared_mutex +# error "__cpp_lib_shared_mutex should not be defined when !defined(_LIBCPP_HAS_NO_THREADS) is not defined!" +# endif # endif -# ifndef __cpp_lib_shared_timed_mutex -# error "__cpp_lib_shared_timed_mutex should be defined in c++2a" -# endif -# if __cpp_lib_shared_timed_mutex != 201402L -# error "__cpp_lib_shared_timed_mutex should have the value 201402L in c++2a" +# if !defined(_LIBCPP_HAS_NO_THREADS) +# ifndef __cpp_lib_shared_timed_mutex +# error "__cpp_lib_shared_timed_mutex should be defined in c++2a" +# endif +# if __cpp_lib_shared_timed_mutex != 201402L +# error "__cpp_lib_shared_timed_mutex should have the value 201402L in c++2a" +# endif +# else +# ifdef __cpp_lib_shared_timed_mutex +# error "__cpp_lib_shared_timed_mutex should not be defined when !defined(_LIBCPP_HAS_NO_THREADS) is not defined!" +# endif # endif #endif // TEST_STD_VER > 17 diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.pass.cpp index 6f7d649..27931b4 100644 --- a/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.pass.cpp +++ b/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.pass.cpp @@ -749,11 +749,17 @@ # error "__cpp_lib_shared_ptr_weak_type should not be defined before c++17" # endif -# ifndef __cpp_lib_shared_timed_mutex -# error "__cpp_lib_shared_timed_mutex should be defined in c++14" -# endif -# if __cpp_lib_shared_timed_mutex != 201402L -# error "__cpp_lib_shared_timed_mutex should have the value 201402L in c++14" +# if !defined(_LIBCPP_HAS_NO_THREADS) +# ifndef __cpp_lib_shared_timed_mutex +# error "__cpp_lib_shared_timed_mutex should be defined in c++14" +# endif +# if __cpp_lib_shared_timed_mutex != 201402L +# error "__cpp_lib_shared_timed_mutex should have the value 201402L in c++14" +# endif +# else +# ifdef __cpp_lib_shared_timed_mutex +# error "__cpp_lib_shared_timed_mutex should not be defined when !defined(_LIBCPP_HAS_NO_THREADS) is not defined!" +# endif # endif # ifndef __cpp_lib_string_udls @@ -873,11 +879,17 @@ # error "__cpp_lib_as_const should have the value 201510L in c++17" # endif -# ifndef __cpp_lib_atomic_is_always_lock_free -# error "__cpp_lib_atomic_is_always_lock_free should be defined in c++17" -# endif -# if __cpp_lib_atomic_is_always_lock_free != 201603L -# error "__cpp_lib_atomic_is_always_lock_free should have the value 201603L in c++17" +# if !defined(_LIBCPP_HAS_NO_THREADS) +# ifndef __cpp_lib_atomic_is_always_lock_free +# error "__cpp_lib_atomic_is_always_lock_free should be defined in c++17" +# endif +# if __cpp_lib_atomic_is_always_lock_free != 201603L +# error "__cpp_lib_atomic_is_always_lock_free should have the value 201603L in c++17" +# endif +# else +# ifdef __cpp_lib_atomic_is_always_lock_free +# error "__cpp_lib_atomic_is_always_lock_free should not be defined when !defined(_LIBCPP_HAS_NO_THREADS) is not defined!" +# endif # endif # ifdef __cpp_lib_atomic_ref @@ -1289,11 +1301,17 @@ # error "__cpp_lib_scoped_lock should have the value 201703L in c++17" # endif -# ifndef __cpp_lib_shared_mutex -# error "__cpp_lib_shared_mutex should be defined in c++17" -# endif -# if __cpp_lib_shared_mutex != 201505L -# error "__cpp_lib_shared_mutex should have the value 201505L in c++17" +# if !defined(_LIBCPP_HAS_NO_THREADS) +# ifndef __cpp_lib_shared_mutex +# error "__cpp_lib_shared_mutex should be defined in c++17" +# endif +# if __cpp_lib_shared_mutex != 201505L +# error "__cpp_lib_shared_mutex should have the value 201505L in c++17" +# endif +# else +# ifdef __cpp_lib_shared_mutex +# error "__cpp_lib_shared_mutex should not be defined when !defined(_LIBCPP_HAS_NO_THREADS) is not defined!" +# endif # endif # if !defined(_LIBCPP_VERSION) @@ -1316,11 +1334,17 @@ # error "__cpp_lib_shared_ptr_weak_type should have the value 201606L in c++17" # endif -# ifndef __cpp_lib_shared_timed_mutex -# error "__cpp_lib_shared_timed_mutex should be defined in c++17" -# endif -# if __cpp_lib_shared_timed_mutex != 201402L -# error "__cpp_lib_shared_timed_mutex should have the value 201402L in c++17" +# if !defined(_LIBCPP_HAS_NO_THREADS) +# ifndef __cpp_lib_shared_timed_mutex +# error "__cpp_lib_shared_timed_mutex should be defined in c++17" +# endif +# if __cpp_lib_shared_timed_mutex != 201402L +# error "__cpp_lib_shared_timed_mutex should have the value 201402L in c++17" +# endif +# else +# ifdef __cpp_lib_shared_timed_mutex +# error "__cpp_lib_shared_timed_mutex should not be defined when !defined(_LIBCPP_HAS_NO_THREADS) is not defined!" +# endif # endif # ifndef __cpp_lib_string_udls @@ -1467,11 +1491,17 @@ # error "__cpp_lib_as_const should have the value 201510L in c++2a" # endif -# ifndef __cpp_lib_atomic_is_always_lock_free -# error "__cpp_lib_atomic_is_always_lock_free should be defined in c++2a" -# endif -# if __cpp_lib_atomic_is_always_lock_free != 201603L -# error "__cpp_lib_atomic_is_always_lock_free should have the value 201603L in c++2a" +# if !defined(_LIBCPP_HAS_NO_THREADS) +# ifndef __cpp_lib_atomic_is_always_lock_free +# error "__cpp_lib_atomic_is_always_lock_free should be defined in c++2a" +# endif +# if __cpp_lib_atomic_is_always_lock_free != 201603L +# error "__cpp_lib_atomic_is_always_lock_free should have the value 201603L in c++2a" +# endif +# else +# ifdef __cpp_lib_atomic_is_always_lock_free +# error "__cpp_lib_atomic_is_always_lock_free should not be defined when !defined(_LIBCPP_HAS_NO_THREADS) is not defined!" +# endif # endif # if !defined(_LIBCPP_VERSION) @@ -1994,11 +2024,17 @@ # error "__cpp_lib_scoped_lock should have the value 201703L in c++2a" # endif -# ifndef __cpp_lib_shared_mutex -# error "__cpp_lib_shared_mutex should be defined in c++2a" -# endif -# if __cpp_lib_shared_mutex != 201505L -# error "__cpp_lib_shared_mutex should have the value 201505L in c++2a" +# if !defined(_LIBCPP_HAS_NO_THREADS) +# ifndef __cpp_lib_shared_mutex +# error "__cpp_lib_shared_mutex should be defined in c++2a" +# endif +# if __cpp_lib_shared_mutex != 201505L +# error "__cpp_lib_shared_mutex should have the value 201505L in c++2a" +# endif +# else +# ifdef __cpp_lib_shared_mutex +# error "__cpp_lib_shared_mutex should not be defined when !defined(_LIBCPP_HAS_NO_THREADS) is not defined!" +# endif # endif # if !defined(_LIBCPP_VERSION) @@ -2021,11 +2057,17 @@ # error "__cpp_lib_shared_ptr_weak_type should have the value 201606L in c++2a" # endif -# ifndef __cpp_lib_shared_timed_mutex -# error "__cpp_lib_shared_timed_mutex should be defined in c++2a" -# endif -# if __cpp_lib_shared_timed_mutex != 201402L -# error "__cpp_lib_shared_timed_mutex should have the value 201402L in c++2a" +# if !defined(_LIBCPP_HAS_NO_THREADS) +# ifndef __cpp_lib_shared_timed_mutex +# error "__cpp_lib_shared_timed_mutex should be defined in c++2a" +# endif +# if __cpp_lib_shared_timed_mutex != 201402L +# error "__cpp_lib_shared_timed_mutex should have the value 201402L in c++2a" +# endif +# else +# ifdef __cpp_lib_shared_timed_mutex +# error "__cpp_lib_shared_timed_mutex should not be defined when !defined(_LIBCPP_HAS_NO_THREADS) is not defined!" +# endif # endif # ifndef __cpp_lib_string_udls -- 2.7.4