<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 - False positive alignment error with -fsanitize=undefined with virtual base"
   href="https://bugs.llvm.org/show_bug.cgi?id=35902">35902</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>False positive alignment error with -fsanitize=undefined with virtual base
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>5.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>-New Bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>securesneakers@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=19654" name="attach_19654" title="Minimal example that reproduces the issue">attachment 19654</a> <a href="attachment.cgi?id=19654&action=edit" title="Minimal example that reproduces the issue">[details]</a></span>
Minimal example that reproduces the issue

Attached program generates false misalignment errors when compiled with
-fsanitize=undefined

$ clang++ --version
clang version 5.0.0 (tags/RELEASE_500/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

$ uname -s -m
Linux x86_64

$ clang++ -std=c++11 -O2 -fsanitize=undefined minimal.cpp && ./a.out
minimal.cpp:9:8: runtime error: constructor call on misaligned address
0x7ffdd1e1e658 for type 'struct Base2', which requires 16 byte alignment

The program crashes afterwards, I have reported a separate bug:
<a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Unaligned movaps in virtual base constructor"
   href="show_bug.cgi?id=35901">https://bugs.llvm.org/show_bug.cgi?id=35901</a>. This bug is about false positive
error.

Attached example contains following hierarchy:

struct alignas(16) Base1 { };
struct Base2 : virtual Base1 { };
struct Base3 : virtual Base2 { };

alignof(Base2) is set to 16 due to alignment of its base class. But when Base3
is instantiated, Base2 is placed with alignment of 8 as it should be according
to Itanium C++ ABI (due to its non-virtual alignment being equal 8):
<a href="https://refspecs.linuxfoundation.org/cxxabi-1.75.html#class-types">https://refspecs.linuxfoundation.org/cxxabi-1.75.html#class-types</a>. Yet
sanitizer complains about alignment not being 16.

Seems that sanitizer checks address using "normal" alignment when "non-virtual
alignment" should be used.

I have reported the same issue for GCC:
<a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83780">https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83780</a></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>