On May 10 14:57, Agner Fog wrote: > Bug description: > > The sqrtl function under Clang causes an access violation when the argument > is negative. > > This error occurs only under Cygwin. > > This error occurs only with the sqrtl function, not with sqrt or sqrtf > > Attached: > > sqrt.cpp: program to reproduce the error. Compile clang sqrt.cpp and run > ./a.exe Thanks for the testcase. This looks like a bug in clang-5.0. It does not occur when building the testcase with gcc, nor does it occur when building with clang-4.0. Looking with GDB, it seems the conversion from float to long double is screwed up. The sequence converting float to long double prior to calling sqrtl is very different: With gcc: Thread 1 "sqrtl" hit Temporary breakpoint 1, main () at sqrtl.c:6 6 float b = sqrtl(a); (gdb) s sqrtl (x=-1) at /home/corinna/src/cygwin/vanilla/winsup/cygwin/math/sqrt.def.h:69 69 __FLT_TYPE res = __FLT_CST (0.0); (gdb) n 70 int x_class = fpclassify (x); (gdb) p x $1 = -1 (gdb) x/4x &x 0xffffcaf0: 0x00000000 0x80000000 0x0004bfff 0x00000006 => 0x100401093 : lea -0x20(%rbp),%rax => 0x100401097 : fstpt -0x30(%rbp) => 0x10040109a : lea -0x30(%rbp),%rdx => 0x10040109e : mov %rax,%rcx => 0x1004010a1 : callq 0x100401110 With clang: Thread 1 "sqrtl" hit Temporary breakpoint 1, main () at sqrtl.c:6 6 float b = sqrtl(a); (gdb) s sqrtl (x=) at /home/corinna/src/cygwin/vanilla/winsup/cygwin/math/sqrt.def.h:69 69 __FLT_TYPE res = __FLT_CST (0.0); (gdb) n 70 int x_class = fpclassify (x); (gdb) p x $1 = (gdb) x/4x &x 0xffffcb10: 0x00000000 0x00000000 0x00040524 0x00000006 => 0x100401096 : movabs $0x100402010,%rax => 0x1004010a0 : flds (%rax) => 0x1004010a2 : mov %rsp,%rax => 0x1004010a5 : fstpt 0x20(%rax) => 0x1004010a8 : callq 0x100401120 Corinna -- Corinna Vinschen Cygwin Maintainer