From c6a2bc2f87e14f81a979d8d648ce1a68a40e9833 Mon Sep 17 00:00:00 2001 From: Aldy Hernandez Date: Fri, 13 Mar 2020 17:12:56 +0100 Subject: Fix infinite loop on truncating widest_irange copies. --- gcc/range-op.cc | 6 +++++- gcc/value-range.cc | 15 ++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'gcc') diff --git a/gcc/range-op.cc b/gcc/range-op.cc index ca87e8e..2e19a3c 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -3332,11 +3332,15 @@ widest_irange_tests () static void multi_precision_range_tests () { - // Test truncating copy. + // Test truncating copy to int_range<1>. int_range<3> big = build_range3 (10, 20, 30, 40, 50, 60); int_range<1> small = big; ASSERT_TRUE (small == int_range<1> (INT (10), INT (60))); + // Test truncating copy to int_range<2>. + int_range<2> medium = big; + ASSERT_TRUE (!medium.undefined_p ()); + // Test that a truncating copy of [MIN,20][22,40][80,MAX] // ends up as a conservative anti-range of ~[21,21]. big = int_range<3> (vrp_val_min (integer_type_node), INT (20)); diff --git a/gcc/value-range.cc b/gcc/value-range.cc index b996708..4a4c487 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -1798,12 +1798,7 @@ irange::intersect (const vrange &vr) void irange::multi_range_union (const irange &r) { - if (undefined_p ()) - { - *this = r; - return; - } - else if (r.undefined_p ()) + if (r.undefined_p ()) return; // Do not worry about merging and such by reserving twice as many @@ -1818,7 +1813,8 @@ irange::multi_range_union (const irange &r) // the merge is performed. // // [Xi,Yi]..[Xn,Yn] U [Xj,Yj]..[Xm,Ym] --> [Xk,Yk]..[Xp,Yp] - signop sign = TYPE_SIGN (type ()); + tree ttype = r.type (); + signop sign = TYPE_SIGN (ttype); // ?? We may need something faster than vectors here, not sure. auto_vec res; wide_int u1 ; @@ -1858,7 +1854,7 @@ irange::multi_range_union (const irange &r) // Now normalize the vector removing any overlaps. i = 2; - int prec = TYPE_PRECISION (type ()); + int prec = TYPE_PRECISION (ttype); wide_int max_val = wi::max_value (prec, sign); for (j = 2; j < k ; j += 2) { @@ -1905,8 +1901,9 @@ irange::multi_range_union (const irange &r) } for (j = 0; j < i ; j++) - m_base[j] = wide_int_to_tree (type (), res [j]); + m_base[j] = wide_int_to_tree (ttype, res [j]); m_num_ranges = i / 2; + m_kind = VR_RANGE; if (flag_checking) check (); -- cgit v1.1