Re: Cubic root of zero gives wrong result with clang 64-bit

Paul FLOYD <[email protected]>
Newsgroups gmane.comp.debugging.valgrind
Message-ID <618449595.2964.1634746588595.JavaMail.www@wwinf1g07>
> Message du 20/10/21 17:14
> De : "Vladislav Yaglamunov" 
> A : [email protected]
> Copie à : 
> Objet : [Valgrind-users] Cubic root of zero gives wrong result with clang 64-bit
> 
>Hi,

>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 
#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


I'll have a go with clang++ at home tonight.

A+
Paul



_______________________________________________
Valgrind-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/valgrind-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.