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

    <tr>
        <th>Summary</th>
        <td>
            Fix compatibility issue between clang and libstdc++ <atomic> with 64-bit atomic struct
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          efriedma-quic
      </td>
    </tr>
</table>

<pre>
    If the 64-bit atomic type is a struct, and its natural alignment is less than 8, clang will generate a call to libatomic.  This call shouldn't be necessary: the "atomic" type has increased alignment, so the variable will be naturally aligned.  Originally reported at #54790

Testcase:

```
#include <atomic>
struct X{char x[8];};
std::atomic<uint64_t> x;
std::atomic<X> x2;
void f() { x = {10}; }
void f2() { x2 = {10}; }
```

Looking at the internal implementation of libstdc++, this boils down to something like:

```
#include <memory>
struct X{char x[8];};
struct alignas(8) Y { X x; };
void f(Y *y, X* val) {
  __atomic_store(std::addressof(y->x), val, 0);
}
```

Original proposed fix at https://reviews.llvm.org/D123642, but @jyknight didn't like that fix, so I'm looking at the alternative of special-casing calls to std::addressof.  b27430f9f should make this easy.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVVE2PmzAQ_TVwGSUiBkI4cNjNdqVKlXrpYXtaGTwEd42d2iZZ_n3Hhv1q1UqVEBh4nnl-b2ZaI-bmcw9-QNgXm1Z64N6MsgM_nxGkAw7O26nzCTsC1wKkd6C5nyxXwJU86RG1D0CFzlEcruEQsJ3i-gRXqRScUKPlHilWx-ndG1CyXfJsAb4NtDv-cIOZlNAJqzy0CBo7isntnOQ3kWHC2LKLFgvBgTuQurPIHYo3PoGAM3HPhVvJW4ULlRB1Ia_mBY6CKHy18iR1_GjxbKwPwTzly8uiqrMku0uym-X-DZ3vKBtxev852WfrtbyynGipSRDp_LiSzj8tPxdB4SGpbruBW3hOyttDUt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