[all-commits] [llvm/llvm-project] 47fafa: [libc++] Fix bug in atomic_ref's calculation of lo...

Louis Dionne via All-commits all-commits at lists.llvm.org
Sat Jul 27 07:03:40 PDT 2024


  Branch: refs/heads/release/19.x
  Home:   https://github.com/llvm/llvm-project
  Commit: 47fafad155a8d8394720dbc689558d304662e205
      https://github.com/llvm/llvm-project/commit/47fafad155a8d8394720dbc689558d304662e205
  Author: Louis Dionne <ldionne.2 at gmail.com>
  Date:   2024-07-27 (Sat, 27 Jul 2024)

  Changed paths:
    M libcxx/include/__atomic/atomic_ref.h
    A libcxx/test/std/atomics/atomics.lockfree/is_always_lock_free.cpp
    R libcxx/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp
    M libcxx/test/std/atomics/atomics.ref/is_always_lock_free.pass.cpp
    M libcxx/test/support/atomic_helpers.h

  Log Message:
  -----------
  [libc++] Fix bug in atomic_ref's calculation of lock_free-ness (#99570)

The builtin __atomic_always_lock_free takes into account the type of the
pointer provided as the second argument. Because we were passing void*,
rather than T*, the calculation failed. This meant that
atomic_ref<T>::is_always_lock_free was only true for char & bool.

This bug exists elsewhere in the atomic library (when using GCC, we fail
to pass a pointer at all, and we fail to correctly align the atomic like
_Atomic would).

This change also attempts to start sorting out testing difficulties with
this function that caused the bug to exist by using the
__GCC_ATOMIC_(CHAR|SHORT|INT|LONG|LLONG|POINTER)_IS_LOCK_FREE predefined
macros to establish an expected value for `is_always_lock_free` and
`is_lock_free` for the respective types, as well as types with matching
sizes and compatible alignment values.

Using these compiler pre-defines we can actually validate that certain
types, like char and int, are actually always lock free like they are on
every platform in the wild.

Note that this patch was actually authored by Eric Fiselier but I picked
up the patch and GitHub won't let me set Eric as the primary author.

Co-authored-by: Eric Fiselier <eric at efcs.ca>
(cherry picked from commit cc1dfb37aa84d1524243b83fadb8ff0f821e03e9)



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