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

Louis Dionne via All-commits all-commits at lists.llvm.org
Fri Jul 26 11:10:27 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: cc1dfb37aa84d1524243b83fadb8ff0f821e03e9
      https://github.com/llvm/llvm-project/commit/cc1dfb37aa84d1524243b83fadb8ff0f821e03e9
  Author: Louis Dionne <ldionne.2 at gmail.com>
  Date:   2024-07-26 (Fri, 26 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>



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