[clang] __builtin_isgreater/__builtin_isgreaterequal/__builtin_isless/__builtin_islessequal/__builtin_islessgreater does not handle unordered comparisons
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
The following code triggers an invalid exception on ABIs that suppors 128 bit float types (either by long double or extended types like __float128):
$ cat t.c
```c
#include
#include
#include
int main (int argc, char *argtv[])
{
feenableexcept (FE_INVALID);
long double qNaN = __builtin_nanl ("");
long double zero = 0;
int r = __builtin_isgreater (zero, qNaN);
printf ("%d\n", r);
}
```
```console
$ clang -target aarch64-linux-gnu t.c -o t -D_GNU_SOURCE -lm
$ ./t
Floating point exception (core dumped)
```
It is not a problem for compiler-rt because it does not support floating point exceptions; but is an issue when using the gcc libgcc. This is triggered by the glibc testsuite when either using clang as the test compiler [1] or by using clang as the built compiler [2].
My plan is to disable an optimization on glibc math.h where isfunction is routed to its builtin conterpart, as least for types different than float and double.
[1] https://sourceware.org/bugzilla/show_bug.cgi?id=33322
[2] https://sourceware.org/git/?p=glibc.git;a=commit;h=be48ae12b10b0556895e356c3ae34b8ca229e61b
Contributor guide
Research direction
Start with the t.c reproducer and the five listed Clang builtins, running it on an ABI with 128-bit floating-point support and FE_INVALID enabled. Then inspect the glibc math.h builtin routing and the linked glibc testsuite cases; done means unordered comparisons no longer raise the invalid exception and the affected tests pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100