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

--- Comment #3 from Vincent Lefèvre <vincent-gcc at vinc17 dot net> ---
(In reply to Andrew Pinski from comment #1)
> Gcc does not know that x will be negative.

Actually, the code should have been (without the volatile):

#include <stdio.h>

int main (void)
{
  double x = -1.0;
  unsigned int i = x;

  printf ("%u\n", i);
  if (x == -1.0)
    printf ("%u\n", i);
  return 0;
}

I don't get the warning either, and due to the "double x = -1.0;", GCC knows
that x is negative.

> -Wconversion might warn about this but I have not tried.

The test is done with -Wconversion.

(In reply to Andrew Pinski from comment #2)
> Also this might be caught at runtime with -fsanitizer=undefined but I have
> not tried yet. Since this is undefined behavior in this case unlike the
> original PR93806.

After checking... This is not undefined behavior, but the value is unspecified.
F.4: "[...] if the floating value is infinite or NaN or if the integral part of
the floating value exceeds the range of the integer type, then the “invalid”
floating-point exception is raised and the resulting value is unspecified."

Reply via email to