[llvm-bugs] [Bug 38931] New: arm backend fails to build some variadic thunks generated by ldc

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Sep 13 05:24:16 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=38931

            Bug ID: 38931
           Summary: arm backend fails to build some variadic thunks
                    generated by ldc
           Product: libraries
           Version: 6.0
          Hardware: Other
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: ARM
          Assignee: unassignedbugs at nondot.org
          Reporter: plugwash at debian.org
                CC: llvm-bugs at lists.llvm.org

Created attachment 20875
  --> https://bugs.llvm.org/attachment.cgi?id=20875&action=edit
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
https://github.com/ldc-developers/ldc/issues/2613 , 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
https://github.com/kinke/ldc/commit/1dda15a76272cdb3963754fa815d96bacc989852.

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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180913/a11c7199/attachment.html>


More information about the llvm-bugs mailing list