> make[3]: Leaving directory `/mnt/scratch/nightly/2006-07-04/i686'
> Comparing stages 2 and 3
> warning: ./cc1-checksum.o differs
> warning: ./cc1plus-checksum.o differs
> warning: ./cc1obj-checksum.o differs
> Bootstrap comparison failure!

Does the attached patch make any difference?

-- 
Eric Botcazou
Index: tree-sra.c
===================================================================
--- tree-sra.c	(revision 115175)
+++ tree-sra.c	(working copy)
@@ -579,6 +579,69 @@ lookup_element (struct sra_elt *parent, 
   return elt;
 }
 
+/* Return true if [MIN, MAX] is a valid range for ARRAY, an ARRAY_TYPE.  */
+
+static bool
+is_valid_array_range (tree min, tree max, tree array)
+{
+  tree t, dom = TYPE_DOMAIN (array);
+
+  /* Watch out for stupid user tricks, indexing outside the array.
+
+     Careful, we're not called only on scalarizable types, so do not
+     assume constant array bounds.  We needn't do anything with such
+     cases, since they'll be referring to objects that we should have
+     already rejected for scalarization, so returning false is fine.  */
+
+  if (dom == NULL)
+    return false;
+
+  t = TYPE_MIN_VALUE (dom);
+  if (!t || TREE_CODE (t) != INTEGER_CST)
+    return false;
+  if (tree_int_cst_lt (min, t))
+    return false;
+
+  t = TYPE_MAX_VALUE (dom);
+  if (!t || TREE_CODE (t) != INTEGER_CST)
+    return false;
+  if (tree_int_cst_lt (t, max))
+    return false;
+
+  return true;
+}
+
+/* Return true if the ARRAY_REF in EXPR is a constant, in bounds access.  */
+
+static bool
+is_valid_const_index (tree expr)
+{
+  tree idx = TREE_OPERAND (expr, 1);
+
+  if (TREE_CODE (idx) != INTEGER_CST)
+    return false;
+
+  return is_valid_array_range (idx, idx, TREE_TYPE (TREE_OPERAND (expr, 0)));
+}
+
+/* Same as above, but for an ARRAY_RANGE_REF.  */
+
+static bool
+is_valid_const_range (tree expr)
+{
+  tree min, max, range_type = TYPE_DOMAIN (TREE_TYPE (expr));
+
+  min = TYPE_MIN_VALUE (range_type);
+  max = TYPE_MAX_VALUE (range_type);
+  if (!min
+      || !max
+      || TREE_CODE (min) != INTEGER_CST
+      || TREE_CODE (max) != INTEGER_CST)
+    return false;
+
+  return is_valid_array_range (min, max, TREE_TYPE (TREE_OPERAND (expr, 0)));
+}
+
 /* Create or return the SRA_ELT structure for EXPR if the expression
    refers to a scalarizable variable.  */
 
@@ -599,7 +662,7 @@ maybe_lookup_element_for_expr (tree expr
 
     case ARRAY_REF:
       /* We can't scalarize variable array indices.  */
-      if (in_array_bounds_p (expr))
+      if (is_valid_const_index (expr))
         child = TREE_OPERAND (expr, 1);
       else
 	return NULL;
@@ -607,7 +670,7 @@ maybe_lookup_element_for_expr (tree expr
 
     case ARRAY_RANGE_REF:
       /* We can't scalarize variable array indices.  */
-      if (range_in_array_bounds_p (expr))
+      if (is_valid_const_range (expr))
 	{
 	  tree domain = TYPE_DOMAIN (TREE_TYPE (expr));
 	  child = build2 (RANGE_EXPR, integer_type_node,
@@ -746,7 +809,7 @@ sra_walk_expr (tree *expr_p, block_stmt_
 	   the effort.  */
 	/* ??? Hack.  Figure out how to push this into the scan routines
 	   without duplicating too much code.  */
-	if (!in_array_bounds_p (inner))
+	if (!is_valid_const_index (inner))
 	  {
 	    disable_scalarization = true;
 	    goto use_all;
@@ -759,7 +822,7 @@ sra_walk_expr (tree *expr_p, block_stmt_
 	break;
 
       case ARRAY_RANGE_REF:
-	if (!range_in_array_bounds_p (inner))
+	if (!is_valid_const_range (inner))
 	  {
 	    disable_scalarization = true;
 	    goto use_all;

Reply via email to