This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix a fallout of PR14179 fix (3.3/3.4/4.0 regression)


Hi!

The following testcase gives ICE since
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&r1=1.1296&r2=1.1297
The problem is:
1) reshape_init_array is using tree_low_cst (, 1), so it should IMHO use
   unsinged HOST_WIDE_INT, not HOST_WIDE_INT
2) not sure what is the reason why sizetype is sign extended instead of zero
   extended, even when it is a unsigned type, but certainly:
  /* Size types *are* sign extended.  */
  sign_extended_type = (!TYPE_UNSIGNED (TREE_TYPE (t))
                        || (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE
                            && TYPE_IS_SIZETYPE (TREE_TYPE (t))));
   0 length arrays use min 0 and max (sizetype) -1, which because of
   this sign extension certainly doesn't fit into unsigned HOST_WIDE_INT,
   and likewise if you have say a char a[0x80000001] = { [0x7fffffff] = 1, 2 }
   on 32-bit target.  Not sure if it is preferrable to use fold_convert
   to size_type_node (which is the same type, but zero extended, not sign
   extended; this is what the patch below does), or simply use
   TREE_INT_CST_LOW for TYPE_IS_SIZETYPE, or make host_integerp special
   case sizetype.  Another alternative would be just to special case
   integer_allonesp (max_index) (that is what zero sized arrays use)
   and don't care at all about >= half of address space arrays (i.e. live
   with ICE in that case or simply clear sized_array_p if !host_integerp
   (max_index, 1)).
Giovanni's patch has been applied to 3.3/3.4 branches and trunk, is this
ok for the same trees?

2004-12-27  Jakub Jelinek  <jakub@redhat.com>

	* decl.c (reshape_init_array): Use UHWI type for max_index_cst
	and index.  Special case sizetype, for which tree_low_cst (, 1)
	doesn't work properly.

	* g++.dg/init/array18.C: New test.

--- gcc/cp/decl.c.jj	2004-12-27 13:00:56.000000000 +0100
+++ gcc/cp/decl.c	2004-12-27 16:26:02.362602782 +0100
@@ -4207,13 +4207,20 @@ reshape_init_array (tree elt_type, tree 
 		    tree *initp, tree new_init)
 {
   bool sized_array_p = (max_index != NULL_TREE);
-  HOST_WIDE_INT max_index_cst = 0;
-  HOST_WIDE_INT index;
+  unsigned HOST_WIDE_INT max_index_cst = 0;
+  unsigned HOST_WIDE_INT index;
 
   if (sized_array_p)
-    /* HWI is either 32bit or 64bit, so it must be enough to represent the
-	array size.  */
-    max_index_cst = tree_low_cst (max_index, 1);
+    {
+      if (host_integerp (max_index, 1))
+	max_index_cst = tree_low_cst (max_index, 1);
+      /* sizetype is sign extended, not zero extended.  */
+      else if (TYPE_IS_SIZETYPE (TREE_TYPE (max_index)))
+	max_index_cst = tree_low_cst (fold_convert (size_type_node, max_index),
+				      1);
+      else
+	gcc_unreachable ();
+    }
 
   /* Loop until there are no more initializers.  */
   for (index = 0;
@@ -4249,7 +4256,14 @@ reshape_init_array (tree elt_type, tree 
 		  TREE_PURPOSE (element_init) = NULL_TREE;
 		}
 	      else
-		index = tree_low_cst (designated_index, 1);
+		{
+		  /* sizetype is sign extended, not zero extended.  */
+		  if (!host_integerp (designated_index, 1)
+		      && TYPE_IS_SIZETYPE (TREE_TYPE (designated_index)))
+		    designated_index = fold_convert (size_type_node,
+						     designated_index);
+		  index = tree_low_cst (designated_index, 1);
+		}
 	    }
 	}
     }
--- gcc/testsuite/g++.dg/init/array18.C.jj	2004-12-27 15:24:03.242953989 +0100
+++ gcc/testsuite/g++.dg/init/array18.C	2004-12-27 15:23:27.000000000 +0100
@@ -0,0 +1,3 @@
+// { dg-do compile }
+double a[0] = { };
+const double b[0][1] = { };

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]