https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109008
--- Comment #34 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Testing I've performed so far (though on 10000 iterations rather than 300000, that is ongoing), once with the https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109008#c33 patch alone, once with that patch and https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109008#c32. First step, generate a random testcase: pr109008-gen.c: #include <stdint.h> #include <stdlib.h> #include <stdio.h> #include <string.h> static long rand_n; static int rand_c; static uint32_t get_rand32 (void) { uint32_t ret = 0; if (rand_c == 0) { ret = random () & 0x7fffffff; rand_c = 31; } else ret = rand_n & (((uint32_t) 1 << rand_c) - 1); ret <<= (32 - rand_c); rand_n = random (); ret |= rand_n & (((uint32_t) 1 << (32 - rand_c)) - 1); rand_n >>= (32 - rand_c); rand_c = 31 - (32 - rand_c); return ret; } static uint64_t get_rand64 (void) { return (((uint64_t) get_rand32 ()) << 32) | get_rand32 (); } static float get_randf (void) { uint32_t i = get_rand32 (); float f; memcpy (&f, &i, sizeof (f)); return f; } int main () { printf ("#define nanf __builtin_nanf (\"\")\n"); printf ("#define inf __builtin_inff ()\n"); for (int n = 0; n < 300000; ++n) { float n1 = get_randf (); float n2 = get_randf (); uint32_t x = get_rand32 (); if ((x & 7) == 0) n2 = n1; x >>= 3; printf ("float f%d (float eps) { float f = ", n); switch (x % 3) { case 0: printf ("%af + eps", n1); break; case 1: printf ("%af - eps", n1); break; case 2: printf ("eps - %af", n1); break; } printf ("; if (f == %af) return eps; return __builtin_nanf (\"42\"); }\n", n2); } return 0; } pr109008-main.c: #include <math.h> #include "pr109008.c" struct S { float (*fn) (float); float lb, ub; }; struct S arr[] = { #include "pr109008.h" }; int main () { float plus_inf = __builtin_inf (); float minus_inf = -plus_inf; for (int i = 0; i < sizeof (arr) / sizeof (arr[0]); ++i) { float lb = nextafterf (arr[i].lb, minus_inf); float ub = nextafterf (arr[i].ub, plus_inf); if (!__builtin_isnan (arr[i].fn (lb)) || !__builtin_isnan (arr[i].fn (ub))) __builtin_printf ("%p err\n", arr[i].fn); } } gcc -g -O2 -o pr109008-gen{,.c}; ./pr109008-gen > pr109008.c Next, with cc1 built with just #c33 patch: rm -f /tmp/ranges; ./cc1 -quiet -O2 pr109008.c; sort -u /tmp/ranges > pr109008.h gcc -g -o pr109008-main{,.c}; ./pr109008-main For 10000 iterations this showed 872 errors. Next, with cc1 built with both #c32 and #c33 patches: rm -f /tmp/ranges; ./cc1 -quiet -O2 pr109008.c; sort -u /tmp/ranges > pr109008.h gcc -g -o pr109008-main{,.c}; ./pr109008-main This didn't print any errors, so at least for foperator_plus and foperator_minus seems to be from this limited testing conservatively correct. Want to finish now this testing also for 300000 iterations and then perhaps try the #c30 patch with variant of #c33 to check also that implementation. And finally compare the #c32+#c33 vs. #c30+#c33variant ranges. Another thing which would be nice to think about is whether float_widen_lhs_range needs to extend even real_{min,max}_representable () bounds towards -+inf, or whether that case can't happen (and check that separately for + or - and * or /), because e.g. for mult/div whether lhs is finite is quite important.