When a floating-point constant is converted to a narrower floating-point type, this conversion is meant to respect the current rounding direction, but GCC does the conversion at compile time even with -frounding-math. Example (tested x86_64 and ARM): float f; void func (void) { f = 1.3L; } fold_convert_const_real_from_real or its caller should avoid such conversions if -frounding-math, unless the conversion is exact.
Confirmed. Note that some callers may expect a constant result anyway (see the TREE_OVERFLOW setting which seems to be overflow indicating...). So fixing this may not be easy without fallout.
*** Bug 80450 has been marked as a duplicate of this bug. ***
note that this may cause the omission of underflow, overflow and inexact exceptions too (so in principle it's an invalid transformation even without -frounding-math but with -ftrapping-math ): float x,y; void f(void) { x = 0x1p-1000; // truncated to 0 y = 0x1p1000; // truncated to inf }
I have a patch fixing fold_convert_const_real_from_real
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>: https://gcc.gnu.org/g:a84b9d5373c7e67fd0ab2a412c22162cdf969c91 commit r12-4764-ga84b9d5373c7e67fd0ab2a412c22162cdf969c91 Author: Richard Biener <rguenther@suse.de> Date: Wed Oct 27 14:27:40 2021 +0200 middle-end/57245 - honor -frounding-math in real truncation The following honors -frounding-math when converting a FP constant to another FP type. 2021-10-27 Richard Biener <rguenther@suse.de> PR middle-end/57245 * fold-const.c (fold_convert_const_real_from_real): Honor -frounding-math if the conversion is not exact. * simplify-rtx.c (simplify_const_unary_operation): Do not simplify FLOAT_TRUNCATE with sign dependent rounding. * gcc.dg/torture/fp-double-convert-float-1.c: New testcase.
This aspect is fixed. For fp<->int converts see PR84407.