[libcxx-commits] [libcxx] Fix bug in atomic_ref's calculation of lock_free-ness. (PR #93427)
Damien L-G via libcxx-commits
libcxx-commits at lists.llvm.org
Fri May 31 07:06:44 PDT 2024
================
@@ -42,6 +42,19 @@ _LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER >= 20
+// These types are required to make __atomic_is_always_lock_free work across GCC and Clang.
+// GCC won't allow the reinterpret_cast<_Tp*>(-required_alignment) trick initially used,
+// so we need to actually fake up an instance of a type with the correct alignment.
+template <size_t _Alignment>
+struct __alignment_checker_type {
+ alignas(_Alignment) char __data;
+};
+
+template <size_t _Alignment>
+struct __get_aligner_instance {
+ static constexpr __alignment_checker_type<_Alignment> __instance{};
----------------
dalg24 wrote:
Any reason for not just inlining the definition of the aligned static object?
```suggestion
alignas(_Alignment) static constexpr char __instance{};
};
```
https://github.com/llvm/llvm-project/pull/93427
More information about the libcxx-commits
mailing list