PATCH RFC: Ensure TREE_TYPE (TYPE_MIN_VALUE (t)) == t

Ian Lance Taylor iant@google.com
Fri Apr 27 18:04:00 GMT 2007


VRP currently assumes that TREE_TYPE (TYPE_MIN_VALUE (t)) == t.  This
shows up in == and != comparisons of values with TYPE_MIN_VALUE of the
value's type.  Those comparisons are normally valid because
build_int_cst_wide uniqifies all integer constants based on the value
and the type.  However, when TREE_TYPE (TYPE_MIN_VALUE (t)) != t, then
any comparison against TYPE_MIN_VALUE will return unequal even if the
values are the same.

PR 31710 provides a test case in which VRP does the wrong thing.  The
problem is noticed by a warning check I recently added.

At the moment TREE_TYPE (TYPE_MIN_VALUE (t)) != t for a typedef,
because build_distinct_type_copy, called from build_variant_type_copy,
simply copies the fields without giving them new types.  I've
bootstrapped and tested the appended patch to fix this.

My question is: do you think this is the right fix, or should we
instead change VRP to use operand_equal_p or simply
tree_int_cst_equal?  My patch seems a little more right, since having
TREE_TYPE (TYPE_MIN_VALUE (t)) == t seems more consistent.  On the
other hand it will increase memory usage for no very obvious gain.

Any thoughts?

(If I commit this patch I will also add the test case from PR 31710).

Ian


2007-04-27  Ian Lance Taylor  <iant@google.com>

	PR middle-end/31710
	* tree.c (build_distinct_type_copy): If TYPE_MIN_VALUE or
	TYPE_MAX_VALUE exist, convert them to the new type.


Index: gcc/tree.c
===================================================================
--- gcc/tree.c	(revision 124119)
+++ gcc/tree.c	(working copy)
@@ -4165,6 +4165,15 @@ build_distinct_type_copy (tree type)
   TYPE_MAIN_VARIANT (t) = t;
   TYPE_NEXT_VARIANT (t) = 0;
   
+  /* VRP assumes that TREE_TYPE (TYPE_MIN_VALUE (type)) == type.  */
+  if (INTEGRAL_TYPE_P (t) || SCALAR_FLOAT_TYPE_P (t))
+    {
+      if (TYPE_MIN_VALUE (t) != NULL_TREE)
+	TYPE_MIN_VALUE (t) = fold_convert (t, TYPE_MIN_VALUE (t));
+      if (TYPE_MAX_VALUE (t) != NULL_TREE)
+	TYPE_MAX_VALUE (t) = fold_convert (t, TYPE_MAX_VALUE (t));
+    }
+
   return t;
 }
 



More information about the Gcc-patches mailing list