<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/84802>84802</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
atomic_is_always_lock_free provides inconsistent results on Apple
</td>
</tr>
<tr>
<th>Labels</th>
<td>
compiler-rt
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ldionne
</td>
</tr>
</table>
<pre>
For a struct of size 16, `atomic_is_always_lock_free` seems to provide inconsistent results based on the address we're passing to the builtin. This seems odd since `is_always_lock_free` should tell us whether *any* instance of that type is lock free, regardless of its address?
```c++
// clang++ x.cpp -std=c++20 -o a.out && ./a.out
#include <iostream>
template <size_t N>
struct Sized { char x[N]; };
template <class T>
void test() {
std::cout << "sizeof(" << typeid(T).name() << ") = " << sizeof(T) << std::endl;
std::cout << "__atomic_always_lock_free(" << typeid(T).name() << ") = " << __atomic_always_lock_free(sizeof(T), 0) << std::endl;
T x;
std::cout << "__atomic_always_lock_free with ptr(" << typeid(T).name() << ") = " << __atomic_always_lock_free(sizeof(T), &x) << std::endl;
std::cout << "__atomic_is_lock_free(" << typeid(T).name() << ") = " << __atomic_is_lock_free(sizeof(T), &x) << std::endl;
}
int main() {
test<Sized<16>>();
}
```
Output:
```
$ clang++ x.cpp -std=c++20 -o a.out && ./a.out
sizeof(5SizedILm16EE) = 16
__atomic_always_lock_free(5SizedILm16EE) = 1
__atomic_always_lock_free with ptr(5SizedILm16EE) = 0
__atomic_is_lock_free(5SizedILm16EE) = 0
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8VU1v4zYQ_TWjyyAGSVmyfdDBsWOgQLE91HeDlsYWW4oUyNEm2V9fUP5Yb-skWyAtIEgQOfP43nA-dIzm6IgqKB6hWGd64NaHyjbGO0fZ3jev1cYH1Bg5DDWjP2A03whlCWqFUArNvjP1zsSdts_6Ne6sr__cHQIRlAIjUReRPfbBfzUNoXG1d9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