<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 - 8 bytes trivially copy constructible and destructible structure passed par memory instead of register"
   href="https://bugs.llvm.org/show_bug.cgi?id=34857">34857</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>8 bytes trivially copy constructible and destructible structure passed par memory instead of register
          </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>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>C++11
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>abdoulk.keita@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The structure X in the following code snippet is both trivially_destructible
and trivially_copyable, but is not pass by register as required but section
3.2.3 of the ABI document
<a href="https://github.com/hjl-tools/x86-psABI/wiki/x86-64-psABI-r252.pdf">https://github.com/hjl-tools/x86-psABI/wiki/x86-64-psABI-r252.pdf</a>

#include <type_traits>

struct X {
    X&operator=(X&&) = delete;
    X&operator=(const X&) = default;
    long x;
};

bool foo() {
    return std::is_trivially_destructible<X>::value;
}

bool bar() {
    return std::is_trivially_copyable<X>::value;
}

int testingfunc(X x){
    return x.x;
}



With clang version >= 5.0 at -O3 -std=c++14 , Compiles to  : 
foo(): # @foo()
  mov al, 1
  ret
bar(): # @bar()
  mov al, 1
  ret

testingfunc(X): # @testingfunc(X)
  mov eax, dword ptr [rdi]
  ret

With clang version <= 4.0.0, and all gcc versions : 
foo(): # @foo()
  mov al, 1
  ret

bar(): # @bar()
  mov al, 1
  ret

testingfunc(X): # @testingfunc(X)
  mov eax, edi
  ret</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>