[libcxx-commits] [libcxx] [libc++] Increase `atomic_ref`'s required alignment for small types (PR #99654)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jul 24 08:32:22 PDT 2024


ldionne wrote:

I'd like to better understand the failure mode here when passing a variable that isn't suitably aligned. It seems that with this patch it becomes pretty easy to violate the `std::atomic_ref::required_alignment`, as can be seen by the failing tests. For example:

```
struct LLIArr2 { long long int i[2]; }
```

Just naively creating a `LLIArr2 x` on the stack and then using it inside an `atomic_ref` can either work or fail the `required_alignment` check depending on the address at which the variable landed. We only catch that loudly in the Extensive and Debug hardening modes -- otherwise it's silent.

What happens when the alignment requirement is not satisfied? Is it only that we will incorrectly report that the `atomic_ref` is always lock free when in reality it uses a lock under the hood due to the incorrect alignment?

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


More information about the libcxx-commits mailing list