#890215 valgrind causes miscalculation on long double

Package:
valgrind
Source:
valgrind
Description:
instrumentation framework for building dynamic analysis tools
Submitter:
Vincent Lefevre
Date:
2023-07-02 09:45:03 UTC
Severity:
important
Tags:
#890215#5
Date:
2018-02-12 02:04:30 UTC
From:
To:
valgrind causes miscalculation on the following program:
----------------------------------------
#include <stdio.h>

int main (void)
{
  volatile union {
    long double d;
    unsigned long i[2];
  } u;

  u.i[0] = 1;
  u.i[1] = 0;
  printf ("%La\n", u.d);

  return 0;
}
----------------------------------------

zira:~> gcc tst.c -o tst
zira:~> ./tst
0x0.000000000000001p-16385
zira:~> valgrind ./tst
==3567== Memcheck, a memory error detector
==3567== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==3567== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==3567== Command: ./tst
==3567==
0x0p+0
==3567==
==3567== HEAP SUMMARY:
==3567==     in use at exit: 0 bytes in 0 blocks
==3567==   total heap usage: 1 allocs, 1 frees, 1,024 bytes allocated
==3567==
==3567== All heap blocks were freed -- no leaks are possible
==3567==
==3567== For counts of detected and suppressed errors, rerun with: -v
==3567== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Instead of 0x0.000000000000001p-16385, one gets 0.

Bug found with MPFR: the tset_ld test fails with valgrind for this
reason.

#890215#10
Date:
2018-02-12 02:34:55 UTC
From:
To:
Control: found -1 1:3.10.0-4
Control: found -1 1:3.12.0~svn20160714-1
[...]

Dame problem on Debian GNU/Linux 8 (jessie) and 9 (stretch).

#890215#19
Date:
2019-07-12 16:38:49 UTC
From:
To:
Control: found -1 1:3.14.0-3
  ^^^^ Same

and ditto with the current stable version.

#890215#28
Date:
2020-06-13 23:18:47 UTC
From:
To:
Control: tags -1 upstream
Control: forwarded -1 https://bugs.kde.org/show_bug.cgi?id=421262
Control: retitle -1 valgrind causes miscalculation on long double

Note that the above value is a subnormal.

This appears to be the same kind of problem as mentioned in a bug
reported upstream last month:

https://bugs.kde.org/show_bug.cgi?id=421262

As said, the cause is that valgrind converts the value to
double precision.

#890215#39
Date:
2023-07-02 09:43:02 UTC
From:
To:
The upstream bug 421262 has been resolved as a duplicate of
bug 197915, which is still open.

I could check that the bug is still present.