[all-commits] [llvm/llvm-project] 59ca61: [libc++] Increase atomic_ref's required alignment ...

Damien L-G via All-commits all-commits at lists.llvm.org
Thu Aug 1 07:39:49 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 59ca618e3b7aec8c32e24d781bae436dc99b2727
      https://github.com/llvm/llvm-project/commit/59ca618e3b7aec8c32e24d781bae436dc99b2727
  Author: Damien L-G <dalg24 at gmail.com>
  Date:   2024-08-01 (Thu, 01 Aug 2024)

  Changed paths:
    M libcxx/include/__atomic/atomic_ref.h
    M libcxx/test/std/atomics/atomics.ref/is_always_lock_free.pass.cpp

  Log Message:
  -----------
  [libc++] Increase atomic_ref's required alignment for small types (#99654)

This patch increases the alignment requirement for std::atomic_ref
such that we can guarantee lockfree operations more often. Specifically,
we require types that are 1, 2, 4, 8, or 16 bytes in size to be aligned
to at least their size to be used with std::atomic_ref.

This is the case for most types, however a notable exception is
`long long` on x86, which is 8 bytes in length but has an alignment
of 4.

As a result of this patch, one has to be more careful about the
alignment of objects used with std::atomic_ref. Failure to provide
a properly-aligned object to std::atomic_ref is a precondition 
violation and is technically UB. On the flipside, this allows us
to provide an atomic_ref that is actually lockfree more often, 
which is an important QOI property.

More information in the discussion at https://github.com/llvm/llvm-project/pull/99570#issuecomment-2237668661.

Co-authored-by: Louis Dionne <ldionne.2 at gmail.com>



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list