<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 generates overaligned load of thrown object"
   href="https://bugs.llvm.org/show_bug.cgi?id=42668">42668</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Clang generates overaligned load of thrown object
          </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>All
          </td>
        </tr>

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

        <tr>
          <th>Keywords</th>
          <td>ABI, miscompilation
          </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>diogo.sampaio@arm.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>diogo.sampaio@arm.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>For the C++ code:
===
#include <arm_neon.h>

int main(void) {
  try {
    throw vld1q_u64(((const uint64_t[2]){1, 2}));
  } catch (uint64x2_t exc) {
    return 0;
  }
  return 1;
}

====
and command:
clang --target=arm-arm-none-eabi -march=armv8-a -c test_upstream.cpp -o - -Os
-o - -S -emit-llvm
====
we obtain this:
entry:
  %exception = tail call i8* @__cxa_allocate_exception(i32 16) #2
  %0 = bitcast i8* %exception to <2 x i64>*
  store <2 x i64> <i64 1, i64 2>, <2 x i64>* %0, align 16, !tbaa !5
========
Which, passing to llc will generate:
   vld1.64 {d16, d17}, [r1]
   vst1.64 {d16, d17}, [r0:128]  << Not 128, but 64!!!
========

The store assumes an alignment of 16. However, %exception has alignment 64 as
defined in
<a href="https://github.com/llvm-mirror/libunwind/blob/master/include/unwind.h">https://github.com/llvm-mirror/libunwind/blob/master/include/unwind.h</a>
where we have:
struct _Unwind_Exception {
 ...
} __attribute__((__aligned__)); //<< For the ARM ABI the largest alignment is 8
(64 bits).

I do believe that the missing "align 8" in %exception should be the root of the
error, as that should be passed further to %0 and, finally, to the store.

I also believe that clang should not assume data-width alignment when the
pointer is a bitcast from a smaller data-type.</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>