[libc-commits] [libc] [libc] fix and explicit atomic difference from c++ (PR #119715)

Schrodinger ZHU Yifan via libc-commits libc-commits at lists.llvm.org
Thu Dec 12 09:17:15 PST 2024


================
@@ -62,6 +62,18 @@ template <typename T> struct Atomic {
     return static_cast<int>(mem_scope);
   }
 
+  LIBC_INLINE static T *addressof(T &ref) { return __builtin_addressof(ref); }
+
+  // require types that are 1, 2, 4, 8, or 16 bytes in length to be aligned to
+  // at least their size to be potentially
+  // used lock-free
+  LIBC_INLINE_VAR static constexpr size_t MIN_ALIGNMENT =
+      (sizeof(T) & (sizeof(T) - 1)) || (sizeof(T) > 16) ? 0 : sizeof(T);
----------------
SchrodingerZhu wrote:

No, it is currently internal to `libc++`. https://github.com/llvm/llvm-project/blob/6edd867e43cb5eb3bb84561c0490e5ebb9d06d90/libcxx/include/__atomic/atomic_ref.h#L110

Also, notice `libc++` is having some troubles with atomics as `__builtin_clear_padding` is not implemented. They will need to refactor their `std::atomic` implementation into a similar form as `atomic_ref`. Hence, code changes in their part are expected.

https://github.com/llvm/llvm-project/pull/119715


More information about the libc-commits mailing list