<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: Wrong tailcalls if varargs function"
   href="https://bugs.llvm.org/show_bug.cgi?id=45234">45234</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>ARM backend: Wrong tailcalls if varargs function
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </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>unassignedbugs@nondot.org
          </td>
        </tr>

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

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>```c++
extern int GetPrimitiveType(int o);
extern double DoubleMethod(int o, ...);
namespace {

double __attribute__((noinline)) Load(int i) {
  double d = DoubleMethod(1, i);
  return d;
}
}

double ParseObject(int o) {
  switch(GetPrimitiveType(o)) {
    case 1:
      return Load(o);
    default:
      return 1.0;
  }
}

```

```asm
_Z11ParseObjecti:
        .fnstart
@ %bb.0:
        .save   {r4, lr}
        push    {r4, lr}
        mov     r4, r0
        bl      _Z16GetPrimitiveTypei
        cmp     r0, #1
        bne     .LBB0_2
@ %bb.1:
        mov     r0, r4
        bl      _ZN12_GLOBAL__N_14LoadEi
        vmov    r0, r1, d0
        pop     {r4, pc}
.LBB0_2:
        vmov.f64        d0, #1.000000e+00
        vmov    r0, r1, d0
        pop     {r4, pc}

```
The caller thinks the return location is d0.

```c++
_ZN12_GLOBAL__N_14LoadEi:
        .fnstart
@ %bb.0:
        mov     r1, r0
        movs    r0, #1
        b       _Z12DoubleMethodiz
```

The tail call to _Z12DoubleMethodiz regardless the calee's cc, which is
probably AAPCS. The AAPCS's  return location for the type double is in r0, r1.


The bug point is at the function 
ARMTargetLowering::IsEligibleForTailCallOptimization in the file
lib/Target/ARM/ARMISelLowering.cpp.
```c++
  if (!CCState::resultsCompatible(CalleeCC, CallerCC, MF, C, Ins,
                                  CCAssignFnForReturn(CalleeCC, isVarArg),
                                  CCAssignFnForReturn(CallerCC, isVarArg)))
    return false;

```

Should be:

```c++
  if (!CCState::resultsCompatible(
          CalleeCC, CallerCC, MF, C, Ins,
          CCAssignFnForReturn(CalleeCC, isVarArg),
          CCAssignFnForReturn(CallerCC, CallerF.isVarArg())))
    return false;

```</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>