<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 --- - alignas with placement new operator generate invalid instruction with sse"
   href="https://llvm.org/bugs/show_bug.cgi?id=24957">24957</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>alignas with placement new operator generate invalid instruction with sse
          </td>
        </tr>

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

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

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

        <tr>
          <th>Reporter</th>
          <td>llvm@gyoo.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>When using alignas, clang will generate the mmx instruction if O1 optimization
or greater are used:
 movaps %xmm0,(%rbx)

But if the memory has been allocated with a new placement operator on a non
16-bytes alignment, it will crash with a coredump


Here a test case:

// clang -std=c++11 -lstdc++ -O0 -g align.cc            # ok
// clang -std=c++11 -lstdc++ -O1 -g align.cc            # coredump because of
MOVAPS on non-aligned 128 bits
// clang -std=c++11 -lstdc++ -O1 -mno-sse -g align.cc   # no more coredump

#include <iostream>


constexpr static int ALIGN_SIZE = 64;

class MyStruct
{
public:
    MyStruct()
    {
        std::cout << "MyStruct: " << this << " " << sizeof(*this) << std::endl
                  << "m_v1: " << &m_v1 << ", m_v2: " << &m_v2 << std::endl;
        m_v1 = 0;
        m_v2 = 0;
    }


private:
   alignas(ALIGN_SIZE) uint64_t m_v1;
   uint64_t m_v2;
};


int main()
{
    size_t offset = 1; // offset not a multiplier of 16 will crash

    char* ptr = new char[sizeof(MyStruct) + offset];
    MyStruct* myStruct = new (ptr+offset) MyStruct;

    return 0;
}</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>