https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113578
Bug ID: 113578 Summary: Incorrect signbit for -nan on RISC-V Product: gcc Version: 11.4.0 Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: redi at gcc dot gnu.org CC: doko at gcc dot gnu.org Target Milestone: --- Target: riscv64-linux-gnu int main() { float f = std::bit_cast<float>(0xfff80000); __builtin_printf("%f %d\n", f, __builtin_signbit(f)); } With no optimization this prints: nan 1 With optimization it prints: -nan 1 i.e. signbit is always set, but sometimes the nan is printed as positive. g++ -v: Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/lib/gcc/riscv64-linux-gnu/11/lto-wrapper Target: riscv64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 11.4.0-1ubuntu1~22.04' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-11 --program-prefix=riscv64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm --disable-libquadmath --disable-libquadmath-support --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --disable-multilib --with-arch=rv64gc --with-abi=lp64d --enable-checking=release --build=riscv64-linux-gnu --host=riscv64-linux-gnu --target=riscv64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=4 Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04) Originally reported to https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1059340 I've only tested this with Ubuntu's gcc, I haven't tried a build of upstream GCC, nor a newer version. Sorry if it's Debian specific.