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]

[PATCH] Fix [0 ... 0] designated initializers


Hi!

The following patch fixes an ICE reported on linux 2.4.x init_task.c where a
designated range was [0 ... 1-1]. Basically the only change (outside of
reformating) is adding if (tree_int_cst_equal (first, last)) last = 0;
Ok to commit?

2001-01-31  Jakub Jelinek  <jakub@redhat.com>

	* c-typeck.c (set_init_index): If first is equal to last, assume as
	if it was not a range at all.

	* gcc.dg/gnu99-init-1.c: Add test for [0 ... 0] range.

--- gcc/c-typeck.c.jj	Mon Jan 29 15:41:58 2001
+++ gcc/c-typeck.c	Wed Jan 31 12:51:45 2001
@@ -5688,21 +5688,27 @@ set_init_index (first, last)
     {
       constructor_index = convert (bitsizetype, first);
 
-      if (last != 0 && tree_int_cst_lt (last, first))
+      if (last)
 	{
-	  error_init ("empty index range in initializer");
-	  last = 0;
-	}
-      else if (last)
-	{
-	  last = convert (bitsizetype, last);
-	  if (constructor_max_index != 0
-	      && tree_int_cst_lt (constructor_max_index, last))
+	  if (tree_int_cst_equal (first, last))
+	    last = 0;
+	  else if (tree_int_cst_lt (last, first))
 	    {
-	      error_init ("array index range in initializer exceeds array bounds");
+	      error_init ("empty index range in initializer");
 	      last = 0;
 	    }
+	  else
+	    {
+	      last = convert (bitsizetype, last);
+	      if (constructor_max_index != 0
+		  && tree_int_cst_lt (constructor_max_index, last))
+		{
+		  error_init ("array index range in initializer exceeds array bounds");
+		  last = 0;
+		}
+	    }
 	}
+
       designator_depth++;
       designator_errorneous = 0;
       if (constructor_range_stack || last)
--- gcc/testsuite/gcc.dg/gnu99-init-1.c.jj	Sat Jan 27 16:56:49 2001
+++ gcc/testsuite/gcc.dg/gnu99-init-1.c	Wed Jan 31 12:53:15 2001
@@ -24,6 +24,7 @@ struct M o[] = { [0 ... 5].O = { [1 ... 
 struct M p[] = { [0 ... 5].O[1 ... 2].K = { [0 ... 1] = 4 },
 		 [5].O[2].K[2] = 5, 6, 7 };
 int q[3][3] = { [0 ... 1] = { [1 ... 2] = 23 }, [1][2] = 24 };
+int r[1] = { [0 ... 1 - 1] = 27 };
 
 int main (void)
 {
@@ -72,6 +73,8 @@ int main (void)
   if (q[1][0] || q[1][1] != 23 || q[1][2] != 24)
     abort ();
   if (q[2][0] || q[2][1] || q[2][2])
+    abort ();
+  if (r[0] != 27)
     abort ();
   exit (0);
 }

	Jakub

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