https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91199

            Bug ID: 91199
           Summary: In -fexcess-precision=standard mode, the warning
                    “floating constant truncated to zero” is misleading
           Product: gcc
           Version: 9.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pascal_cuoq at hotmail dot com
  Target Milestone: ---

Consider the following program:

#include <stdio.h>
#include <float.h>

#define MY_HUGE_VALF 0x1.0p255f

float f;

int main(void) {
  f = 0x1.0p-255f * MY_HUGE_VALF;
  printf("%d, %f\n", (int)FLT_EVAL_METHOD, f);
}

When compiled with -O -fexcess-precision=standard -mfpmath=387 and executed,
this program prints “2, 1.000000”, which indicates that neither factor is 0 and
neither is +inf.
Compiler Explorer link: https://gcc.godbolt.org/z/RA_tDw

This all corresponds exactly to the C standard [1] and Joseph Myers's post [2]
introducing the option -fexcess-precision=standard, but please look at the
warnings emitted during compilation:

<source>:9:3: warning: floating constant truncated to zero [-Woverflow]

<source>:9:3: warning: floating constant exceeds range of 'float' [-Woverflow]

The second warning, about MY_HUGE_VALF, is not wrong, and probably corresponds
to an aspect of the program that should be brought to the attention of the
developer.

The first warning is wrong: it implies that 0x1.0p-255f will be interpreted as
0 by the compiler, while it (correctly) isn't.

I would suggest to make the first warning more like the second one, along the
lines of “floating constant underflows range of 'float'”.

[1] https://port70.net/~nsz/c/c11/n1570.html#5.2.4.2.2p9
[2] https://gcc.gnu.org/ml/gcc-patches/2008-11/msg00105.html

Reply via email to