From: Aldy Hernandez Date: Wed, 24 May 2023 17:55:09 +0000 (+0200) Subject: Disallow setting of NANs in frange setter unless setting trees. X-Git-Tag: basepoints/gcc-15~8949 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fae324f1901aff86be3183d87447eddaf33ec262;p=thirdparty%2Fgcc.git Disallow setting of NANs in frange setter unless setting trees. frange::set() is confusing in that we can set a NAN by specifying a bound of +-NAN, even though we tecnically disallow NANs in the setter because the kind can never be VR_NAN. This is a wart for get_tree_range(), which builds a range out of a tree from the source, to work correctly. It's ugly, and it showed its limitation while implementing LTO streaming of ranges. This patch disallows passing NAN bounds in frange::set() and fixes get_tree_range. gcc/ChangeLog: * value-query.cc (range_query::get_tree_range): Set NAN directly if necessary. * value-range.cc (frange::set): Assert that bounds are not NAN. --- diff --git a/gcc/value-query.cc b/gcc/value-query.cc index 43297f17c396..a84f164d77bd 100644 --- a/gcc/value-query.cc +++ b/gcc/value-query.cc @@ -189,9 +189,16 @@ range_query::get_tree_range (vrange &r, tree expr, gimple *stmt) { frange &f = as_a (r); REAL_VALUE_TYPE *rv = TREE_REAL_CST_PTR (expr); - f.set (TREE_TYPE (expr), *rv, *rv); - if (!real_isnan (rv)) - f.clear_nan (); + if (real_isnan (rv)) + { + bool sign = real_isneg (rv); + f.set_nan (TREE_TYPE (expr), sign); + } + else + { + nan_state nan (false); + f.set (TREE_TYPE (expr), *rv, *rv, nan); + } return true; } diff --git a/gcc/value-range.cc b/gcc/value-range.cc index 2f37ff3e58e0..707b1f15fd40 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -359,14 +359,7 @@ frange::set (tree type, gcc_unreachable (); } - // Handle NANs. - if (real_isnan (&min) || real_isnan (&max)) - { - gcc_checking_assert (real_identical (&min, &max)); - bool sign = real_isneg (&min); - set_nan (type, sign); - return; - } + gcc_checking_assert (!real_isnan (&min) && !real_isnan (&max)); m_kind = kind; m_type = type;