[libcxx-commits] [libcxx] 9c97e4e - [libc++] [P0482] [C++20] Implement missing bits for atomic

Marek Kurdej via libcxx-commits libcxx-commits at lists.llvm.org
Tue Nov 24 12:08:06 PST 2020


Author: Marek Kurdej
Date: 2020-11-24T21:07:57+01:00
New Revision: 9c97e4ef4529ee2b518af6c1f2f68d2634946b3a

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

LOG: [libc++] [P0482] [C++20] Implement missing bits for atomic

Added: ATOMIC_CHAR8_T_LOCK_FREE, atomic<char8_t>, atomic_char8_t.
http://wg21.link/P0482

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D91706

Added: 
    

Modified: 
    libcxx/include/atomic
    libcxx/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp
    libcxx/test/std/atomics/atomics.lockfree/lockfree.pass.cpp
    libcxx/test/std/atomics/atomics.types.generic/integral.pass.cpp
    libcxx/test/std/atomics/atomics.types.generic/integral_typedefs.pass.cpp
    libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_helpers.h
    libcxx/test/std/atomics/types.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/include/atomic b/libcxx/include/atomic
index 70f17699c224..26522560f47d 100644
--- a/libcxx/include/atomic
+++ b/libcxx/include/atomic
@@ -48,6 +48,7 @@ template <class T> T kill_dependency(T y) noexcept;
 
 #define ATOMIC_BOOL_LOCK_FREE unspecified
 #define ATOMIC_CHAR_LOCK_FREE unspecified
+#define ATOMIC_CHAR8_T_LOCK_FREE unspecified // C++20
 #define ATOMIC_CHAR16_T_LOCK_FREE unspecified
 #define ATOMIC_CHAR32_T_LOCK_FREE unspecified
 #define ATOMIC_WCHAR_T_LOCK_FREE unspecified
@@ -465,6 +466,7 @@ typedef atomic<long>               atomic_long;
 typedef atomic<unsigned long>      atomic_ulong;
 typedef atomic<long long>          atomic_llong;
 typedef atomic<unsigned long long> atomic_ullong;
+typedef atomic<char8_t>            atomic_char8_t; // C++20
 typedef atomic<char16_t>           atomic_char16_t;
 typedef atomic<char32_t>           atomic_char32_t;
 typedef atomic<wchar_t>            atomic_wchar_t;
@@ -1125,6 +1127,9 @@ _Tp kill_dependency(_Tp __y) _NOEXCEPT
 #if defined(__CLANG_ATOMIC_BOOL_LOCK_FREE)
 # define ATOMIC_BOOL_LOCK_FREE      __CLANG_ATOMIC_BOOL_LOCK_FREE
 # define ATOMIC_CHAR_LOCK_FREE      __CLANG_ATOMIC_CHAR_LOCK_FREE
+#ifndef _LIBCPP_NO_HAS_CHAR8_T
+# define ATOMIC_CHAR8_T_LOCK_FREE   __CLANG_ATOMIC_CHAR8_T_LOCK_FREE
+#endif
 # define ATOMIC_CHAR16_T_LOCK_FREE  __CLANG_ATOMIC_CHAR16_T_LOCK_FREE
 # define ATOMIC_CHAR32_T_LOCK_FREE  __CLANG_ATOMIC_CHAR32_T_LOCK_FREE
 # define ATOMIC_WCHAR_T_LOCK_FREE   __CLANG_ATOMIC_WCHAR_T_LOCK_FREE
@@ -1136,6 +1141,9 @@ _Tp kill_dependency(_Tp __y) _NOEXCEPT
 #elif defined(__GCC_ATOMIC_BOOL_LOCK_FREE)
 # define ATOMIC_BOOL_LOCK_FREE      __GCC_ATOMIC_BOOL_LOCK_FREE
 # define ATOMIC_CHAR_LOCK_FREE      __GCC_ATOMIC_CHAR_LOCK_FREE
+#ifndef _LIBCPP_NO_HAS_CHAR8_T
+# define ATOMIC_CHAR8_T_LOCK_FREE   __GCC_ATOMIC_CHAR8_T_LOCK_FREE
+#endif
 # define ATOMIC_CHAR16_T_LOCK_FREE  __GCC_ATOMIC_CHAR16_T_LOCK_FREE
 # define ATOMIC_CHAR32_T_LOCK_FREE  __GCC_ATOMIC_CHAR32_T_LOCK_FREE
 # define ATOMIC_WCHAR_T_LOCK_FREE   __GCC_ATOMIC_WCHAR_T_LOCK_FREE
@@ -1450,6 +1458,9 @@ template<> struct __cxx_is_always_lock_free<bool> { enum { __value = 2 == ATOMIC
 template<> struct __cxx_is_always_lock_free<char> { enum { __value = 2 == ATOMIC_CHAR_LOCK_FREE }; };
 template<> struct __cxx_is_always_lock_free<signed char> { enum { __value = 2 == ATOMIC_CHAR_LOCK_FREE }; };
 template<> struct __cxx_is_always_lock_free<unsigned char> { enum { __value = 2 == ATOMIC_CHAR_LOCK_FREE }; };
+#ifndef _LIBCPP_NO_HAS_CHAR8_T
+template<> struct __cxx_is_always_lock_free<char8_t> { enum { __value = 2 == ATOMIC_CHAR8_T_LOCK_FREE }; };
+#endif
 template<> struct __cxx_is_always_lock_free<char16_t> { enum { __value = 2 == ATOMIC_CHAR16_T_LOCK_FREE }; };
 template<> struct __cxx_is_always_lock_free<char32_t> { enum { __value = 2 == ATOMIC_CHAR32_T_LOCK_FREE }; };
 template<> struct __cxx_is_always_lock_free<wchar_t> { enum { __value = 2 == ATOMIC_WCHAR_T_LOCK_FREE }; };
@@ -2721,6 +2732,9 @@ typedef atomic<long>               atomic_long;
 typedef atomic<unsigned long>      atomic_ulong;
 typedef atomic<long long>          atomic_llong;
 typedef atomic<unsigned long long> atomic_ullong;
+#ifndef _LIBCPP_NO_HAS_CHAR8_T
+typedef atomic<char8_t>            atomic_char8_t;
+#endif
 typedef atomic<char16_t>           atomic_char16_t;
 typedef atomic<char32_t>           atomic_char32_t;
 typedef atomic<wchar_t>            atomic_wchar_t;

diff  --git a/libcxx/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp b/libcxx/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp
index d9e09641dc4b..d9ec69eebbe2 100644
--- a/libcxx/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp
+++ b/libcxx/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp
@@ -74,6 +74,9 @@ void run()
     CHECK_ALWAYS_LOCK_FREE(char);
     CHECK_ALWAYS_LOCK_FREE(signed char);
     CHECK_ALWAYS_LOCK_FREE(unsigned char);
+#if TEST_STD_VER > 17 && defined(__cpp_char8_t)
+    CHECK_ALWAYS_LOCK_FREE(char8_t);
+#endif
     CHECK_ALWAYS_LOCK_FREE(char16_t);
     CHECK_ALWAYS_LOCK_FREE(char32_t);
     CHECK_ALWAYS_LOCK_FREE(wchar_t);
@@ -122,6 +125,9 @@ void run()
     static_assert(std::atomic<char>::is_always_lock_free == (2 == ATOMIC_CHAR_LOCK_FREE), "");
     static_assert(std::atomic<signed char>::is_always_lock_free == (2 == ATOMIC_CHAR_LOCK_FREE), "");
     static_assert(std::atomic<unsigned char>::is_always_lock_free == (2 == ATOMIC_CHAR_LOCK_FREE), "");
+#if TEST_STD_VER > 17 && defined(__cpp_char8_t)
+    static_assert(std::atomic<char8_t>::is_always_lock_free == (2 == ATOMIC_CHAR8_T_LOCK_FREE), "");
+#endif
     static_assert(std::atomic<char16_t>::is_always_lock_free == (2 == ATOMIC_CHAR16_T_LOCK_FREE), "");
     static_assert(std::atomic<char32_t>::is_always_lock_free == (2 == ATOMIC_CHAR32_T_LOCK_FREE), "");
     static_assert(std::atomic<wchar_t>::is_always_lock_free == (2 == ATOMIC_WCHAR_T_LOCK_FREE), "");

diff  --git a/libcxx/test/std/atomics/atomics.lockfree/lockfree.pass.cpp b/libcxx/test/std/atomics/atomics.lockfree/lockfree.pass.cpp
index 064afcaa7ed6..e36e46815e5f 100644
--- a/libcxx/test/std/atomics/atomics.lockfree/lockfree.pass.cpp
+++ b/libcxx/test/std/atomics/atomics.lockfree/lockfree.pass.cpp
@@ -12,6 +12,7 @@
 
 // #define ATOMIC_BOOL_LOCK_FREE unspecified
 // #define ATOMIC_CHAR_LOCK_FREE unspecified
+// #define ATOMIC_CHAR8_T_LOCK_FREE unspecified // C++20
 // #define ATOMIC_CHAR16_T_LOCK_FREE unspecified
 // #define ATOMIC_CHAR32_T_LOCK_FREE unspecified
 // #define ATOMIC_WCHAR_T_LOCK_FREE unspecified
@@ -34,6 +35,11 @@ int main(int, char**)
     assert(ATOMIC_CHAR_LOCK_FREE == 0 ||
            ATOMIC_CHAR_LOCK_FREE == 1 ||
            ATOMIC_CHAR_LOCK_FREE == 2);
+#if TEST_STD_VER > 17 && defined(__cpp_char8_t)
+    assert(ATOMIC_CHAR8_T_LOCK_FREE == 0 ||
+           ATOMIC_CHAR8_T_LOCK_FREE == 1 ||
+           ATOMIC_CHAR8_T_LOCK_FREE == 2);
+#endif
     assert(ATOMIC_CHAR16_T_LOCK_FREE == 0 ||
            ATOMIC_CHAR16_T_LOCK_FREE == 1 ||
            ATOMIC_CHAR16_T_LOCK_FREE == 2);

diff  --git a/libcxx/test/std/atomics/atomics.types.generic/integral.pass.cpp b/libcxx/test/std/atomics/atomics.types.generic/integral.pass.cpp
index 62ef06bcc16e..12edd299a1ac 100644
--- a/libcxx/test/std/atomics/atomics.types.generic/integral.pass.cpp
+++ b/libcxx/test/std/atomics/atomics.types.generic/integral.pass.cpp
@@ -180,6 +180,9 @@ int main(int, char**)
     test<std::atomic_ulong, unsigned long>();
     test<std::atomic_llong, long long>();
     test<std::atomic_ullong, unsigned long long>();
+#if TEST_STD_VER > 17 && defined(__cpp_char8_t)
+    test<std::atomic_char8_t, char8_t>();
+#endif
 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
     test<std::atomic_char16_t, char16_t>();
     test<std::atomic_char32_t, char32_t>();

diff  --git a/libcxx/test/std/atomics/atomics.types.generic/integral_typedefs.pass.cpp b/libcxx/test/std/atomics/atomics.types.generic/integral_typedefs.pass.cpp
index dd59c301a8e0..74827ecdef33 100644
--- a/libcxx/test/std/atomics/atomics.types.generic/integral_typedefs.pass.cpp
+++ b/libcxx/test/std/atomics/atomics.types.generic/integral_typedefs.pass.cpp
@@ -21,6 +21,7 @@
 // typedef atomic<unsigned long>      atomic_ulong;
 // typedef atomic<long long>          atomic_llong;
 // typedef atomic<unsigned long long> atomic_ullong;
+// typedef atomic<char8_t>            atomic_char8_t; // C++20
 // typedef atomic<char16_t>           atomic_char16_t;
 // typedef atomic<char32_t>           atomic_char32_t;
 // typedef atomic<wchar_t>            atomic_wchar_t;
@@ -56,6 +57,9 @@ int main(int, char**)
     static_assert((std::is_same<std::atomic<long long>, std::atomic_llong>::value), "");
     static_assert((std::is_same<std::atomic<unsigned long long>, std::atomic_ullong>::value), "");
     static_assert((std::is_same<std::atomic<wchar_t>, std::atomic_wchar_t>::value), "");
+#if TEST_STD_VER > 17 && defined(__cpp_char8_t)
+    static_assert((std::is_same<std::atomic<char8_t>, std::atomic_char8_t>::value), "");
+#endif
 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
     static_assert((std::is_same<std::atomic<char16_t>, std::atomic_char16_t>::value), "");
     static_assert((std::is_same<std::atomic<char32_t>, std::atomic_char32_t>::value), "");

diff  --git a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_helpers.h b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_helpers.h
index cab2264aaecd..9c21ada4da7e 100644
--- a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_helpers.h
+++ b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_helpers.h
@@ -83,6 +83,9 @@ struct TestEachIntegralType {
         TestFunctor<long long>()();
         TestFunctor<unsigned long long>()();
         TestFunctor<wchar_t>();
+#if TEST_STD_VER > 17 && defined(__cpp_char8_t)
+        TestFunctor<char8_t>()();
+#endif
 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
         TestFunctor<char16_t>()();
         TestFunctor<char32_t>()();

diff  --git a/libcxx/test/std/atomics/types.pass.cpp b/libcxx/test/std/atomics/types.pass.cpp
index 4fc2c6c22a7b..ed6cbef33aeb 100644
--- a/libcxx/test/std/atomics/types.pass.cpp
+++ b/libcxx/test/std/atomics/types.pass.cpp
@@ -112,6 +112,9 @@ int main(int, char**)
     test<unsigned long>      ();
     test<long long>          ();
     test<unsigned long long> ();
+#if TEST_STD_VER > 17 && defined(__cpp_char8_t)
+    test<char8_t>            ();
+#endif
     test<char16_t>           ();
     test<char32_t>           ();
     test<wchar_t>            ();


        


More information about the libcxx-commits mailing list