<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - clang miscompiles atomics by using optimized libcalls for underaligned storage"
   href="https://llvm.org/bugs/show_bug.cgi?id=23263">23263</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang miscompiles atomics by using optimized libcalls for underaligned storage
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>richard-llvm@metafoo.co.uk
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Per <a href="https://gcc.gnu.org/wiki/Atomic/GCCMM/LIbrary">https://gcc.gnu.org/wiki/Atomic/GCCMM/LIbrary</a>, "All the optimized routines
expect that the object will be properly aligned for a data type of the
specified size".

However, Clang and GCC get this wrong:

  struct X { int a, b; };
  X f(X *p) { X r; __atomic_load(p, &r, 5); return r; }

... calls __atomic_load_8. And GCC's libatomic implements __atomic_load_8 on
x86_64 with a single 8-byte mov, which is only atomic for a correctly-aligned
operand.

We should instead emit a call to __atomic_load(8, p, &r, 5) because we have no
reason to think that p is 8 byte aligned.

The same happens for __atomic_store and probably all the other atomic libcalls.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>