[libcxx-commits] [PATCH] D119931: [libcxx][atomic] Remove workaround for PR31864

Kai Luo via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Feb 16 04:37:13 PST 2022


lkail created this revision.
lkail requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

I believe the origin issue in PR31864 has been addressed by https://reviews.llvm.org/D59566.

As discussed in https://github.com/llvm/llvm-project/issues/53840, `ATOMIC_LLONG_LOCK_FREE == 2` sometimes is not consistent with `std::atomic<long long>::is_always_lock_free`, since the macro takes `long long`'s ABI alignment into account.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119931

Files:
  libcxx/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp


Index: libcxx/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp
===================================================================
--- libcxx/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp
+++ libcxx/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp
@@ -29,38 +29,18 @@
     assert(std::atomic<T>().is_lock_free());
 }
 
-// FIXME: This separate test is needed to work around llvm.org/PR31864
-// which causes ATOMIC_LLONG_LOCK_FREE to be defined as '1' in 32-bit builds
-// even though __atomic_always_lock_free returns true for the same type.
-constexpr bool NeedWorkaroundForPR31864 =
-#if defined(__clang__)
-(sizeof(void*) == 4); // Needed on 32 bit builds
-#else
-false;
-#endif
-
-template <bool Disable = NeedWorkaroundForPR31864,
-  std::enable_if_t<!Disable>* = nullptr,
-  class LLong = long long,
-  class ULLong = unsigned long long>
-void checkLongLongTypes() {
-  static_assert(std::atomic<LLong>::is_always_lock_free == (2 == ATOMIC_LLONG_LOCK_FREE), "");
-  static_assert(std::atomic<ULLong>::is_always_lock_free == (2 == ATOMIC_LLONG_LOCK_FREE), "");
-}
-
-// Used to make the calls to __atomic_always_lock_free dependent on a template
-// parameter.
-template <class T> constexpr size_t getSizeOf() { return sizeof(T); }
-
-template <bool Enable = NeedWorkaroundForPR31864,
-  std::enable_if_t<Enable>* = nullptr,
-  class LLong = long long,
-  class ULLong = unsigned long long>
 void checkLongLongTypes() {
-  constexpr bool ExpectLockFree = __atomic_always_lock_free(getSizeOf<LLong>(), 0);
-  static_assert(std::atomic<LLong>::is_always_lock_free == ExpectLockFree, "");
-  static_assert(std::atomic<ULLong>::is_always_lock_free == ExpectLockFree, "");
-  static_assert((0 != ATOMIC_LLONG_LOCK_FREE) == ExpectLockFree, "");
+  static_assert(std::atomic<long long>::is_always_lock_free == __atomic_always_lock_free(sizeof(long long), 0), "");
+  static_assert(std::atomic<unsigned long long>::is_always_lock_free ==
+                    __atomic_always_lock_free(sizeof(unsigned long long), 0),
+                "");
+  static_assert(__atomic_always_lock_free(sizeof(long long), (long long*)alignof(long long)) ==
+                    (2 == ATOMIC_LLONG_LOCK_FREE),
+                "");
+  static_assert(
+      __atomic_always_lock_free(sizeof(unsigned long long), (unsigned long long*)alignof(unsigned long long)) ==
+          (2 == ATOMIC_LLONG_LOCK_FREE),
+      "");
 }
 
 void run()


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119931.409204.patch
Type: text/x-patch
Size: 2447 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220216/7b3e3513/attachment.bin>


More information about the libcxx-commits mailing list