Issue 244639
Summary [Clang][Headers] tgmath.h conj of a real argument returns x + 0i instead of x - 0i
Labels clang
Assignees
Reporter shalseth
    For a real argument, `conj` from clang's `<tgmath.h>` returns the argument converted to complex, `x + 0i`. C requires the macro to invoke the complex function for a real argument (C11 7.25p5). `conj (x + 0i)` is `x - 0i`, so the sign of the imaginary part is wrong.

```c
#include <tgmath.h>
#include <stdio.h>

int
main (void)
{
  volatile double x = 1.0;
  double _Complex z = conj (x);
  printf ("%+g\n", cimag (z));
 return 0;
}
```

```
$ clang -O2 t.c -lm && ./a.out
+0
$ gcc -O2 t.c -lm && ./a.out
-0
```

GCC uses glibc's `<tgmath.h>` here. With clang, `conj ((double _Complex) x)` gives -0 too. The cause is the real overloads of `__tg_conj` in clang/lib/Headers/tgmath.h, which `return __x;`. `__tg_cproj` already calls `cprojf`/`cproj`/`cprojl` for real arguments.

glibc's math/test-tgmath2 checks that `conj` of a real argument calls the complex function. With a clang-built glibc it fails on those lines (https://github.com/sparclinux/issues/issues/96).

LLVM main 1ed0efd70af1, SPARC M7, Linux sparc64. The header is target independent.

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to