<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - __atomic_load_8 assumes 8 byte alignment"
   href="https://bugs.llvm.org/show_bug.cgi?id=47188">47188</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>__atomic_load_8 assumes 8 byte alignment
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>compiler-rt
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>11.0
          </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>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>builtins
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>tijl@coosemans.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>For the following code (found in Glasgow Haskell Compiler), clang generates a
function call to __atomic_load_8 on x86 (32-bit) because long long is 8 bytes
in size but only 4 byte aligned:

long long test( long long *x ) {
  return( __atomic_load_n( x, __ATOMIC_SEQ_CST ));
}

For 8 byte aligned types clang uses the FILDLL instruction, which (according to
the Intel SDM Vol 3) loads 8 bytes atomically as long as they don't cross a
cache line boundary, which is guaranteed when they are 8 byte aligned but not
with 4 byte alignment.

The problem now is that libcompiler_rt casts the argument of __atomic_load_8 to
an _Atomic( long long ) pointer which has 8 byte alignment so clang uses the
FILDLL instruction when compiling libcompiler_rt.

I don't know if the bug is in libcompiler_rt or in clang.  Maybe
__atomic_load_n should only accept atomic types like __c11_atomic_load does.</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>