Issue 108904
Summary ppc64el miscompilation on signed integer argument passing
Labels new issue
Assignees
Reporter tpearson-ssc
    On all Clang versions after Clang 16, llc miscompiles a simple C++ test program testing integer argument passing:

```
#include <stdio.h>
#include <math.h>

int main() {
        volatile double result;

        volatile int exp = -53;
        volatile double base = 3635833917682146;

 result = ldexp(base, exp);
        printf("Result: %f\n", result);

        return 0;
}
```

The program should output `0.403659`, but on Clang 17 and newer outputs `inf`.

On calling ldexp, `r4` is used to pass `exp`.  Unfortunately, only the lower 32 bits of `exp` are passed in `r4`, leading to an incorrect result.  This is due to incorrect backend code generation:

```
  8bc:  60 00 3f c8     lfd f1,96(r31)
- 8c0:  6e 00 9f e8     lwa     r4,108(r31)		<-- CORRECT (sign extends values for signed 64-bit integer parameter passing in r4)
+ 8c0:  6c 00 9f 80     lwz     r4,108(r31)		<-- WRONG (zeroes upper 32 bits of parameter in r4)
  8c4:  9d fd ff 4b     bl      660 <0000001b.plt_call.ldexp@@GLIBC_2.17>
  8c8:  18 00 41 e8     ld r2,24(r1)
  8cc:  70 00 3f d8     stfd    f1,112(r31)
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to