[llvm-bugs] [Bug 45234] New: ARM backend: Wrong tailcalls if varargs function

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Mar 18 00:25:36 PDT 2020


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

            Bug ID: 45234
           Summary: ARM backend: Wrong tailcalls if varargs function
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: manjian2006 at gmail.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org

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

```

-- 
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/20200318/93c3a1d3/attachment-0001.html>


More information about the llvm-bugs mailing list