From: Aldy Hernandez Date: Mon, 24 May 2021 17:57:29 +0000 (+0200) Subject: VARYING ranges of different sizes should not be equal. X-Git-Tag: basepoints/gcc-13~7294 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ca8cc8273c5646482eedd567288b9f8aa3fb6492;p=thirdparty%2Fgcc.git VARYING ranges of different sizes should not be equal. VARYING ranges are just normal ranges that span the entire domain. Such ranges have had end-points for a few releases now, and the fact that the legacy code was still treating all VR_VARYING the same was an oversight. This patch fixes the oversight to match the multi-range behavior. gcc/ChangeLog: * value-range.cc (irange::legacy_equal_p): Check type when comparing VR_VARYING types. (range_tests_legacy): Test comparing VARYING ranges of different sizes. --- diff --git a/gcc/value-range.cc b/gcc/value-range.cc index 865344fcc3e7..8d7b46c0239d 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -28,6 +28,7 @@ along with GCC; see the file COPYING3. If not see #include "ssa.h" #include "tree-pretty-print.h" #include "fold-const.h" +#include "gimple-range.h" // Here we copy between any two irange's. The ranges can be legacy or // multi-ranges, and copying between any combination works correctly. @@ -454,8 +455,10 @@ irange::legacy_equal_p (const irange &other) const if (m_kind != other.m_kind) return false; - if (m_kind == VR_UNDEFINED || m_kind == VR_VARYING) + if (m_kind == VR_UNDEFINED) return true; + if (m_kind == VR_VARYING) + return range_compatible_p (type (), other.type ()); return (vrp_operand_equal_p (tree_lower_bound (0), other.tree_lower_bound (0)) && vrp_operand_equal_p (tree_upper_bound (0), @@ -2245,6 +2248,14 @@ range_tests_legacy () copy = legacy_range; ASSERT_TRUE (copy.varying_p ()); } + + // VARYING of different sizes should not be equal. + int_range_max r0 (integer_type_node); + int_range_max r1 (short_integer_type_node); + ASSERT_TRUE (r0 != r1); + value_range vr0 (integer_type_node); + int_range_max vr1 (short_integer_type_node); + ASSERT_TRUE (vr0 != vr1); } // Simulate -fstrict-enums where the domain of a type is less than the