Bug 436398 - R NAs and NaN payload when converting 80-bit and 64-bit numbers on x87
Summary: R NAs and NaN payload when converting 80-bit and 64-bit numbers on x87
Status: REPORTED
Alias: None
Product: valgrind
Classification: Developer tools
Component: vex (other bugs)
Version First Reported In: 3.15 SVN
Platform: Compiled Sources Linux
: NOR wishlist
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-04-30 11:26 UTC by Tomas Kalibera
Modified: 2021-04-30 11:26 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments
Quick hack to preserve NaN payload which fixes observed issue. (737 bytes, patch)
2021-04-30 11:26 UTC, Tomas Kalibera
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tomas Kalibera 2021-04-30 11:26:32 UTC
Created attachment 138026 [details]
Quick hack to preserve NaN payload which fixes observed issue.

VEX does not preserve NaN payload bits when converting between 80-bit and 64-bit floating point numbers in convert_f80le_to_f64le and convert_f64le_to_f80le.

This causes trouble when using valgrind to run R. R uses a special NaN payload to distinguish R NA ("missing") values from usual NaNs that result from floating point computations.

One way to reproduce is to run

R -d valgrind --quiet -e "sum(c(1, NA))"

with R compiled with gcc -O0  (with -O2, different code is generated and the problem does not appear). I tried on Ubuntu 20.04 (gcc 9.3, valgrind 3.15.0)

When R is run this way, the result is "NaN". When it is run without valgrind, it is "NA" (which it should be). It would be nice, if possible, if valgrind could match the underlying platform in this case.

The attached patch is an experiment/hack which confirms the cause is  convert_f80le_to_f64le/convert_f64le_to_f80le: with the patch applied, R returns "NA", matching the platform behavior, when running the example.