From: Paul F. <pj...@wa...> - 2021-10-20 18:13:12
|
On 10/20/21 16:16, Paul FLOYD wrote: >> Message du 20/10/21 17:14 >> De : "Vladislav Yaglamunov" >> A : val...@li... >> Copie à : >> Objet : [Valgrind-users] Cubic root of zero gives wrong result with clang 64-bit >> >> I am using Valgrind 3.17.0 and noticed a strange behavior while running a code compiled with clang: > #include >> int main() { >> long double x = std::cbrtl(0.0L); >> printf("%Lf", x); >> >> return 0; >> } > I just did a test with g++. I had to modify the code a bit to prevent the compiler replacing the cbrtl() call with just a zero: > > #include <cmath> > #include < > > int main() { > volatile long double arg{0.0L}; > long double x = std::cbrtl(arg); > printf("%Lf", x); > > return 0; > } > > This seems to work OK, both default and -m32. > > > The asm for that is > > 00000000004011a5 : > 4011a5: 55 push %rbp > 4011a6: 48 89 e5 mov %rsp,%rbp > 4011a9: 48 83 ec 20 sub $0x20,%rsp > 4011ad: d9 ee fldz > 4011af: db 7d e0 fstpt -0x20(%rbp) > 4011b2: db 6d e0 fldt -0x20(%rbp) > 4011b5: 48 8d 64 24 f0 lea -0x10(%rsp),%rsp > 4011ba: db 3c 24 fstpt (%rsp) > 4011bd: e8 8e fe ff ff callq 401050 > 4011c2: 48 83 c4 10 add $0x10,%rsp > 4011c6: db 7d f0 fstpt -0x10(%rbp) > 4011c9: ff 75 f8 pushq -0x8(%rbp) > 4011cc: ff 75 f0 pushq -0x10(%rbp) > 4011cf: bf 04 20 40 00 mov $0x402004,%edi > 4011d4: b8 00 00 00 00 mov $0x0,%eax > 4011d9: e8 62 fe ff ff callq 401040 > 4011de: 48 83 c4 10 add $0x10,%rsp > 4011e2: b8 00 00 00 00 mov $0x0,%eax > 4011e7: c9 leaveq > 4011e8: c3 retq Well, it works with clang++: FreeBSD clang version 11.0.1 (gi...@gi...:llvm/llvm-project.git llvmorg-11.0. 1-0-g43ff75f2c3fe) Target: x86_64-unknown-freebsd13.0 I also tried clang++ 8, 9 and 12. The asm for clang++12 for my modified code is 0000000000201920 <main>: 201920: 55 push %rbp 201921: 48 89 e5 mov %rsp,%rbp 201924: 48 83 ec 40 sub $0x40,%rsp 201928: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%rbp) 20192f: d9 ee fldz 201931: db 7d e0 fstpt -0x20(%rbp) 201934: db 6d e0 fldt -0x20(%rbp) 201937: 48 89 e0 mov %rsp,%rax 20193a: db 38 fstpt (%rax) 20193c: e8 bf 00 00 00 call 201a00 <cbrtl@plt> 201941: db 7d d0 fstpt -0x30(%rbp) 201944: db 6d d0 fldt -0x30(%rbp) 201947: 48 89 e0 mov %rsp,%rax 20194a: db 38 fstpt (%rax) 20194c: bf c9 05 20 00 mov $0x2005c9,%edi 201951: 31 c0 xor %eax,%eax 201953: e8 b8 00 00 00 call 201a10 <printf@plt> 201958: 31 c0 xor %eax,%eax 20195a: 48 83 c4 40 add $0x40,%rsp 20195e: 5d pop %rbp 20195f: c3 ret Can you post the asm that you are getting ? I'll see if I can try clang on Fedora 34. A+ Paul |