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

    <tr>
        <th>Summary</th>
        <td>
            x86-32 -mno-x87 64-bit atomic load miscompilation
        </td>
    </tr>

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

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

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

<pre>
    https://gcc.godbolt.org/z/K11bWenvT
clang 16.0.0 with `-O3 -m32 -std=c++11 -march=i586 -mno-x87 -g0`

```C++
#include <atomic>

const std::atomic_ullong v = {1};

static unsigned long long f() {
    auto p = &v;
 asm("" : "+r"(p): : "memory");
    return *p;
}

int main() {
    return f();
}
```

this compiles to a `cmpxchg8b` on read-only memory, which causes `SIGSEGV`. iirc atomic loads from read-only memory should work according to the C++ spec.

https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/Can.20.60Atomic*.3A.3Aload.60.20perform.20a.20write/near/387172509

cc @chorman0773
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxsVMGOpDYQ_ZriUgKZcreBA4fu6WUV5ZDDRskxMsYN3gUb2aZ7Zr8-AnoyvdmVLBtV1Xs8uV5ZhmB6q3UNxzMcL4lc4uB8PXvXezlN2n-V33TSuu6tHmKcA_ATUAPU9EplvetaN8bM-R6o-Q7U_J7n7d_a3v4EdgF2UqO0PeYiYxnDu4kDgmDpHxzTiROmIXbALwroDHTOc0wn6dUA_GKOpcB0si59LQtMewaC7YyPXbB9vezYR5S4sWpcOo3AX2R0k1HAPz0DlbMh4vbfE_DTXvPPMo7O9nhD4BeE4pxDcQF-fgaGKKNRuNjtujrcANt2BSqBqhW3lyIiyiU6nHc-Erf_yFCGaasnIELgJ9w-z347yhmo2oJ7YtKT829bqvqgQESv4-ItAp3mD53F5VmwsREnaeyv1D3gD-W_YHi_3mfCOJiAyk2zGXXA6FCuzVTT_KqGvmxBMHQWvZZd6uz4hu_iX_A-GDWgkkvQYcV8-e3zl0-f_wLBMjTGK9zbgKOTXcCrd9NPNBgGt4wd3p3_hlIp5ztj-1VFHDQ-XIBh1ip71vyjZf0SYro6Mvu-jGZWg4yZctOW5FZ67-5ATYheyzWYc0FlnsbUzUGvgehmo4CaF2kzYplgp91idMr4ulb9mWAZsVn7q_NTRkxmxO7eRA3UWC09UMPLIi_oyKofjKkQDkwNzk_SsqLgSVfzruKVTHSdi4oqygteJUNdXEXLDlqz7nCtSF7bQhYl08VVsq68CpWYmhhxVtKRMUZ5lRXXsiuFLgvJKy4OBRyYnqQZs3G8TevwJiaERdfiUIkqGWWrx7C9B0RW33FLriY8XhJfr5i0XfoABzaaEMMHSzRx1PVrKdJ1uN-nVxzS1sTnHuNkwm4kGY2zyeLH_z8uJg5L-2jOyv840tm7r1pFoGZTFYCaTfW_AQAA__9vVmXa">