<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/64829>64829</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            C++20's P0528R3/P1123R0 not implemented (atomic ignoring padding bits)
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          comex
      </td>
    </tr>
</table>

<pre>
    C++20 includes [P0528R3](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0528r3.html) and [P1123R0](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1123r0.html), which together require `std::atomic<T>::compare_exchange_strong` and `std::atomic_ref<T>::compare_exchange_strong` to ignore any padding bits that exist in `T`.

However, this is not implemented in Clang or libc++ as of b41e75c8a42256cca4305f534b88d1d13711e10e.  Also, neither paper is mentioned on the [cxx_status page](https://clang.llvm.org/cxx_status.html).

As a result of the missing implementation, the following prints 0 when it should print 1:
```cpp
#include <atomic>
#include <stdio.h>
int main() {
 struct HasPadding { char a; short b; };
    HasPadding expected{};
 std::atomic<HasPadding> atomic(expected);
    ((char *)&expected)[1] = 0x42; // update padding byte
    printf("%d\n", atomic.compare_exchange_strong(
        expected, expected));
}
```

[See also: [this comment](https://github.com/rust-lang/unsafe-code-guidelines/issues/449#issuecomment-1677985851) which includes a comparison of different compilers.]
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VcuO47gO_RplQySwKD8XWeTRQS8bfXtfkCXGVsORfCW5k_r7gexUJYWqGcxmgiCRJZPnkDykZAims0RbVuxZcVzJKfbOb5W70G3VOv26PTDcM9xjBsaqYdIUgBX7H1mB9U_BiiPDuo9xDEzsGJ4Ynq7X68aNZNch6o3zHcPT76g4w1NQiOmFDtOTdiowPI1yJJ8WmPE6PSfPXmz6eBkYNiCtngE5R_Ez-y8Ak2efvQ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