public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Allow copying of symbolic ranges to an irange.
@ 2020-09-15 15:57 Aldy Hernandez
  2020-09-15 19:59 ` Andrew MacLeod
  0 siblings, 1 reply; 4+ messages in thread
From: Aldy Hernandez @ 2020-09-15 15:57 UTC (permalink / raw)
  To: Andrew MacLeod, gcc-patches

This fixes an ICE when trying to copy a legacy value_range containing a 
symbolic to a multi-range:

	min = make_ssa_name (type);
	max = build_int_cst (type, 55);
	value_range vv (min, max);
	int_range<2> vr = vv;

This doesn't affect anything currently, as we don't have a lot of 
interactions between value_range's and multi_range's in trunk right, but 
it will become a problem as soon as someone tries to get a range from 
evrp and copy it over to a multi-range.

OK pending tests?

gcc/ChangeLog:

	* range-op.cc (multi_precision_range_tests): Normalize symbolics when 
copying to a multi-range.
	* value-range.cc (irange::copy_legacy_range): Add test.
---
  gcc/range-op.cc    |  9 +++++++++
  gcc/value-range.cc | 12 +++++++++++-
  2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index c5f511422f4..8e52d5318e9 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -3463,6 +3463,15 @@ multi_precision_range_tests ()
    small = big;
    ASSERT_TRUE (small == int_range<1> (INT (21), INT (21), VR_ANTI_RANGE));

+  // Copying a legacy symbolic to an int_range should normalize the
+  // symbolic at copy time.
+  {
+    value_range legacy_range (make_ssa_name (integer_type_node), INT (25));
+    int_range<2> copy = legacy_range;
+    ASSERT_TRUE (copy == int_range<2>  (vrp_val_min (integer_type_node),
+					INT (25)));
+  }
+
    range3_tests ();
  }

diff --git a/gcc/value-range.cc b/gcc/value-range.cc
index 20aa4f114c9..26ccd143e5c 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -101,7 +101,17 @@ irange::copy_legacy_range (const irange &src)
  	   VR_ANTI_RANGE);
      }
    else
-    set (src.min (), src.max (), VR_RANGE);
+    {
+      // If copying legacy to int_range, normalize any symbolics.
+      if (src.legacy_mode_p () && !range_has_numeric_bounds_p (&src))
+	{
+	  value_range cst (src);
+	  cst.normalize_symbolics ();
+	  set (cst.min (), cst.max ());
+	  return;
+	}
+      set (src.min (), src.max ());
+    }
  }

  // Swap min/max if they are out of order.  Return TRUE if further
-- 
2.26.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-09-16 18:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-15 15:57 [PATCH] Allow copying of symbolic ranges to an irange Aldy Hernandez
2020-09-15 19:59 ` Andrew MacLeod
2020-09-16 16:25   ` Aldy Hernandez
2020-09-16 18:43     ` Andrew MacLeod

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).