<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 - clang-cl: SIMD vector elements are unaligned in Microsoft's std::array and std::tuple"
   href="https://bugs.llvm.org/show_bug.cgi?id=41480">41480</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang-cl: SIMD vector elements are unaligned in Microsoft's std::array and std::tuple
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>8.0
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Windows NT
          </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>new bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>andreas.zapf@ableton.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>As a result, code using std::array's and std::tuple's with SIMD vector elements
crashes due to unaligned memory access.

It seems that the behavior of "#pragma pack" is the underlying issue.
Microsoft's std::array and std::tuple are declared with #pragma pack(8)
(exactly "#pragma pack(push,_CRT_PACKING)"), and it seems that in clang-cl
"#pragma pack" beats alignment of SIMD types while in cl it's the other way
around.

To reproduce, compile the following example:
clang-cl -c

#include <emmintrin.h>
#include <array>
#include <tuple>

std::array<__m128, 1> arr;
static_assert(alignof(decltype(arr)) >= alignof(__m128), "unaligned array");

std::tuple<__m128> tpl;
static_assert(alignof(decltype(tpl)) >= alignof(__m128), "unaligned tuple");</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>