[libcxx-commits] [libcxx] [libc++] Fix bug in atomic_ref's calculation of lock_free-ness (PR #99570)

James Y Knight via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jul 19 06:52:21 PDT 2024


jyknight wrote:

I agree that we should definitely increase the required alignment of small types to allow them to be used lock-free.

> stl requires types with size power of 2, up to 2x pointer size, to be aligned on their size value.
> libstdc++ requires types of size 1, 2, 4, 8, and 16 bytes in length to be aligned to max(sizeof(T), alignof(T))

These are nearly the same thing. You cannot legitimately align a `T` below `alignof(T)`, regardless of what `atomic_ref<T>::required_alignment` says. For user-friendliness, it seems preferable to never report an alignment below `alignof(T)`, so I think the `max(sizeof(T), alignof(T))` version is better.

The other difference is whether to require 16-byte alignment for a 16-byte object on a 32-bit platform. I don't think that matters much, so I'd just go with libstdc++'s choice.

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


More information about the libcxx-commits mailing list