<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 - arm backend fails to build some variadic thunks generated by ldc"
   href="https://bugs.llvm.org/show_bug.cgi?id=38931">38931</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>arm backend fails to build some variadic thunks generated by ldc
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>6.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Other
          </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>Backend: ARM
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>plugwash@debian.org
          </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=20875" name="attach_20875" title="test cases">attachment 20875</a> <a href="attachment.cgi?id=20875&action=edit" title="test cases">[details]</a></span>
test cases

Background:

ldc generates "thunks" which adjust the "this" pointer before calling the
original function. I understand these are related to multiple inheritance.

It was discovered that "thunks" for variadic functions were being miscompiled
<a href="https://github.com/ldc-developers/ldc/issues/2613">https://github.com/ldc-developers/ldc/issues/2613</a> , the variadic arguments were
not being passed on correctly to the original function. It turns out that
variadic functions can only be passed on correctly in a tail call (most ABIs
don't pass on any meta-information about the number of variadics, so there is
no real way to copy the variadics).

The fix was to make ldc specify "musttail" (which is an order) rather than
"tail" (which is a hint) when generating thunks for variadic functions
<a href="https://github.com/kinke/ldc/commit/1dda15a76272cdb3963754fa815d96bacc989852">https://github.com/kinke/ldc/commit/1dda15a76272cdb3963754fa815d96bacc989852</a>.

The issue:

llvm sometimes fails to compile such thunks on arm, with the error "failed to
perform tail call elimination on a call site marked musttail".

I extracted one of the failing thunks into a llvm assembler file and
experimented with different parameter lists. I build the test files with "clang
-S <filename>"

test2.ll -- the original case from ldc, parameter list consists of the this
pointer, followed by two structures each containing a 32-bit integer and a
pointer, followed by the variadics. This case fails.

test3.ll -- parameter lists consists of the this pointer and the variadics.
This test builds successfully and results in sane assembler output.

test4.ll -- parameter list consists of the this pointer, followed by one
structure containing a 32-bit integer and a pointer, followed by the variadics.
This test builds successfully and results in sane assembler output.

test5.ll -- parameter list consists of the this pointer, followed by one
structure containing a 32-bit integer and a pointer, followed by two 32-bit
integers followed by the variadics. This test builds successfully and results
in assembler output that looks inefficient but correct.

test6.ll -- parameter list consists of the this pointer, followed by one
structure containing a 32-bit integer and a pointer, followed by three 32-bit
integers followed by the variadics. This test builds successfully and results
in assembler output that looks inefficient but correct.

My observation from these test cases is that the trigger for the failure
appears to be a structure parameter passed on the stack. Structures passed in
registers seem to be ok as do integer/pointer parameters passed on the stack.

All of the test cases build successfully on i386.</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>