Hi! The following testcase ICEs, because when !HONOR_NANS but HONOR_SIGNED_ZEROS, if we see lhs = op1 * op2; and know that lhs is [-0.0, 0.0] and op2 is [0.0, 0.0], the division of these two yields UNDEFINED and clear_nan () on it fails an assert. With HONOR_NANS it would actually result in a known NAN, but when NANs aren't honored, we clear the NAN bits. Now, for the above case we actually don't know anything about the op1 range (except that it isn't a NAN/INF because of !HONOR_NANS !HONOR_INFINITIES), so I think the best is just to return VARYING for the case we get UNDEFINED as well.
If we want, the op[12]_range methods perhaps can handle the corner cases earlier separately, say for lhs [0.0, 0.0] and op2 [0.0, 0.0] when HONOR_SIGNED_ZEROS this would be just [0.0, MAX]. Bootstrapped/regtested on x86_64-linux and i686-linux, preapproved by Aldy in the PR, committed to trunk. 2022-11-16 Jakub Jelinek <ja...@redhat.com> PR tree-optimization/107668 * range-op-float.cc (float_binary_op_range_finish): Set VARYING also when r is UNDEFINED. * gcc.dg/ubsan/pr107668.c: New test. --- gcc/range-op-float.cc.jj 2022-11-14 19:33:32.514881313 +0100 +++ gcc/range-op-float.cc 2022-11-15 09:25:57.956137343 +0100 @@ -1891,8 +1891,9 @@ float_binary_op_range_finish (bool ret, // or the reverse operation introduced a known NAN. // Say for lhs = op1 * op2 if lhs is [-0, +0] and op2 is too, // 0 / 0 is known NAN. Just punt in that case. + // If NANs aren't honored, we get for 0 / 0 UNDEFINED, so punt as well. // Or if lhs is a known NAN, we also don't know anything. - if (r.known_isnan () || lhs.known_isnan ()) + if (r.known_isnan () || lhs.known_isnan () || r.undefined_p ()) { r.set_varying (type); return true; --- gcc/testsuite/gcc.dg/ubsan/pr107668.c.jj 2022-11-15 09:24:40.281189629 +0100 +++ gcc/testsuite/gcc.dg/ubsan/pr107668.c 2022-11-15 09:24:40.281189629 +0100 @@ -0,0 +1,12 @@ +/* PR tree-optimization/107668 */ +/* { dg-do compile } */ +/* { dg-options "-ffast-math -fno-associative-math -fsanitize=float-cast-overflow -fno-guess-branch-probability -fsigned-zeros" } */ + +_Complex int c; +int i; + +void +foo (void) +{ + c /= (_Complex) i; +} Jakub