[libc++] Always query the compiler to find whether a type is always lockfree
authorLouis Dionne <ldionne.2@gmail.com>
Tue, 6 Sep 2022 21:07:18 +0000 (17:07 -0400)
committerLouis Dionne <ldionne.2@gmail.com>
Mon, 19 Sep 2022 15:10:02 +0000 (11:10 -0400)
commitf1a601fe88f99d52ca80617266897b217bcd4d64
tree641683e6761d36ec457510475ebd6ed51af3d597
parent0a4c946abcfaae3601c49a55e29944287f867b7f
[libc++] Always query the compiler to find whether a type is always lockfree

In https://llvm.org/D56913, we added an emulation for the __atomic_always_lock_free
compiler builtin when compiling in Freestanding mode. However, the emulation
did (and could not) give exactly the same answer as the compiler builtin,
which led to a potential ABI break for e.g. enum classes.

After speaking to the original author of D56913, we agree that the correct
behavior is to instead always use the compiler builtin, since that provides
a more accurate answer, and __atomic_always_lock_free is a purely front-end
builtin which doesn't require any runtime support. Furthermore, it is
available regardless of the Standard mode (see https://godbolt.org/z/cazf3ssYY).

However, this patch does constitute an ABI break. As shown by https://godbolt.org/z/1eoex6zdK:
- In LLVM <= 11.0.1, an atomic<enum class with 1 byte> would not contain a lock byte.
- In LLVM >= 12.0.0, an atomic<enum class with 1 byte> would contain a lock byte.

This patch breaks the ABI again to bring it back to 1 byte, which seems
like the correct thing to do.

Fixes #57440

Differential Revision: https://reviews.llvm.org/D133377
libcxx/docs/ReleaseNotes.rst
libcxx/include/atomic
libcxx/test/libcxx/atomics/atomics.align/align.pass.cpp
libcxx/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp