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.
---
 gcc/value-query.cc | 13 ++++++++++---
 gcc/value-range.cc |  9 +--------
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/gcc/value-query.cc b/gcc/value-query.cc
index 43297f17c39..a84f164d77b 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 <frange> (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 2f37ff3e58e..707b1f15fd4 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;
-- 
2.40.1

Reply via email to