When I try to run some unit tests, I met this problem
[ RUN ] DumpDataExtractorTest.Formats /home/emmmer/git/llvm-project/lldb/unittests/Core/DumpDataExtractorTest.cpp:90: Failure Expected equality of these values: expected Which is: "{-nan -nan nan nan}" result.GetString() Which is: "{nan nan nan nan}" [ FAILED ] DumpDataExtractorTest.Formats (25 ms)
So I extracted a minimal repro from lldb/source/Core/DumpDataExtractor.cpp:53 half2float(uint16_t half) .
#include <stdio.h> #include <math.h> #include <stdint.h> #include <string.h> int main() { float f = 0; *(uint32_t *) &f = 0xffffe000; float w = f * ldexpf(1, -112); printf("%f(%x)\n", w, *(uint32_t *) &w); return 0; }
On x86_64 it runs correctly.
GNU gdb (Debian 10.1-1.7) 10.1.90.20210103-git Copyright (C) 2021 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This GDB was configured as "x86_64-linux-gnu". Reading symbols from nan... (gdb) b main Breakpoint 1 at 0x113d: file nan.c, line 7. (gdb) r Starting program: /home/emmmer/nan Breakpoint 1, main () at nan.c:7 7 float f = 0; (gdb) n 8 *(uint32_t *) &f = 0xffffe000; (gdb) n 9 float w = f * ldexpf(1, -112); (gdb) n 10 printf("%f(%x)\n", w, *(uint32_t *) &w); (gdb) p w $1 = -nan(0x7fe000) \\ -nan expected (gdb) p f $2 = -nan(0x7fe000)
But on riscv64, it seems to meet some problem.
c GNU gdb (GDB) openEuler 11.1-2.oe2203 Copyright (C) 2021 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> Reading symbols from nan... (gdb) b main Breakpoint 1 at 0x105e8: file nan.c, line 7. (gdb) r Starting program: /root/nan [Thread debugging using libthread_db enabled] Using host libthread_db library "/usr/lib64/libthread_db.so.1". Breakpoint 1, main () at nan.c:7 7 float f = 0; (gdb) n n8 *(uint32_t *) &f = 0xffffe000; (gdb) n 9 float w = f * ldexpf(1, -112); (gdb) n 10 printf("%f(%x)\n", w, *(uint32_t *) &w); (gdb) p w $1 = nan(0x400000) \\ -nan expected (gdb) p f $2 = -nan(0x7fe000)
The problem occurs after line 9, the nan payload got lost after the float multiplication.
The problem only happens when running float16 tests, due to riscv standard does not enforce NaN payload propagation, so I would like to turn it off temporarily on the riscv platform, until more investigations are taken.
Add a brief comment with the reason, "riscv does not support...." just a one liner.