Incorrect floating point eval method on x86 targets in soft float mode
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Consider a small program in C language:
```c
unsigned fun(double a) {
return a;
}
```
When compiled with `clang -m32 -fno-pie -O3 -msoft-float -mno-sse -mno-x87` it correctly produces a library call for software floating point support ([godbolt](https://godbolt.org/z/sTor39boW)):
```asm
fun:
sub esp, 20
push dword ptr [esp + 28]
push dword ptr [esp + 28]
call __fixunsdfsi
add esp, 28
ret
```
The same will gcc do, although it does not need `-mno-x87` ([godbolt](https://godbolt.org/z/d9eE5x6zj)).
Things change when we want to ensure correct floating point eval method is used by appending a static assertion:
```c
_Static_assert(__FLT_EVAL_METHOD__ == 0, "Why?");
unsigned fun(double a) {
return a;
}
```
While gcc compiler continues to work fine ([godbolt](https://godbolt.org/z/rrM8fPW19)), clang errors with `__FLT_EVAL_METHOD__` being set to 2 ([godbolt](https://godbolt.org/z/P9eqcvhPh)), which is wrong in this particular scenario. Trying to enforce the correct value by passing `-ffp-eval-method=source` will also fail with `setting the floating point evaluation method to source on a target without SSE is not supported` message ([godbolt](https://godbolt.org/z/1P3xc6nGd)).
To summarise:
1. Clang incorrectly sets `__FLT_EVAL_METHOD__` for x86 (both 32-bit and 64-bit) in soft floating point mode. Should be 0.
2. Clang incorrectly shows a -Wpragma warning when passing `-ffp-eval-method=source` on x86 (both 32-bit and 64-bit) in soft floating point mode.
Both issues were apparently introduced by https://github.com/llvm/llvm-project/commit/1592d88aa7bc13c9f53cf09d25b98e7318a57bfb, cc @zahiraam.
Contributor guide
Assessment
This issue has not been assessed yet.