Skip to content

is_always_lock_free Returns Incorrect Value For 128 Bit Struct On ARM64 #75081

Open
@insertinterestingnamehere

Description

With clang 17.1 on ARM64 I'm seeing std::atomic<T>::is_always_lock_free evaluate to true even though the member function std::atomic<T>::is_lock_free() evaluates to false for the same type.

Here's a minimal example:

#include <atomic>
#include <cstdint>
#include <iostream>

struct bigint_equiv {
  uint64_t first, second;
};

int main() {
  std::atomic<bigint_equiv> a;
  std::cout << a.is_lock_free() << " " << decltype(a)::is_always_lock_free << std::endl;
}

Possibly related: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70814 where the gcc devs discuss why libatomic doesn't allow 128 bit atomics to be lock-free on ARM.

When I compile the same code with gcc 13.2 is_always_lock_free is false which is strange since I've confirmed that the same libstdc++ is being included and linked. This also appears to be what happens on godbolt too though. With gcc the assembly (as best I can tell) shows a 0 being written out (https://godbolt.org/z/T7493K8xP) while with clang the assembly shows a 1 (https://godbolt.org/z/Gb35jMfjr).

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions