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

Vladislav Yaglamunov <[email protected]>
Newsgroups gmane.comp.debugging.valgrind
Message-ID <CAKuWCJYFmmCoMgxU6vdaVs5ANHD+HgH22nZ5DBwVN=99FJ+XkQ@mail.gmail.com>
Hi,

I am using Valgrind 3.17.0 and noticed a strange behavior while running a
code compiled with clang:

#include <cmath>
#include <cstdio>

int main() {
    long double x = std::cbrtl(0.0L);
    printf("%Lf", x);

    return 0;
}

This example gives complete wrong output:

clang++ cbrtl.cpp -o cbrtl && valgrind ./cbrtl
==338929== Memcheck, a memory error detector
==338929== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==338929== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright
info
==338929== Command: ./cbrtl
==338929==
-0.178840
==338929==
==338929== HEAP SUMMARY:
==338929==     in use at exit: 0 bytes in 0 blocks
==338929==   total heap usage: 2 allocs, 2 frees, 73,728 bytes allocated
==338929==
==338929== All heap blocks were freed -- no leaks are possible
==338929==
==338929== For lists of detected and suppressed errors, rerun with: -s
==338929== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

However, using -m32 option for clang or gcc compiler (both 32 and 64-bit)
prints 0.0 as expected. I know that valgrind does not support 80-bit long
double and converts it to 64-bit.
I think it might cause this issue as the original code is compiled for
80-bit long doubles. It also might be an issue with clang.

Regards,
Vlad Yaglamunov

_______________________________________________
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.