OSDN Git Service

* c-typeck.c (really_start_incremental_init): Discriminate
authordj <dj@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 21 Sep 2001 00:27:59 +0000 (00:27 +0000)
committerdj <dj@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 21 Sep 2001 00:27:59 +0000 (00:27 +0000)
between zero-length arrays and flexible arrays.
(push_init_level): Detect zero-length arrays and handle them
like fixed-sized arrays.
* expr.c (store_constructor): Handle zero-length arrays and
flexible arrays correctly.
* doc/extend.texi: Update zero-length array notes.

* gcc.dg/20000926-1.c: Update expected warning messages.
* gcc.dg/array-2.c: Likewise, and test for warnings too.
* gcc.dg/array-4.c: Likewise, and don't verify the zero-length
array.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@45714 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/c-typeck.c
gcc/doc/extend.texi
gcc/expr.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/20000926-1.c
gcc/testsuite/gcc.dg/array-2.c
gcc/testsuite/gcc.dg/array-4.c

index c0190fc..1419033 100644 (file)
@@ -1,3 +1,13 @@
+2001-09-20  DJ Delorie  <dj@redhat.com>
+
+       * c-typeck.c (really_start_incremental_init): Discriminate
+       between zero-length arrays and flexible arrays.
+       (push_init_level): Detect zero-length arrays and handle them
+       like fixed-sized arrays.
+       * expr.c (store_constructor): Handle zero-length arrays and
+       flexible arrays correctly.
+       * doc/extend.texi: Update zero-length array notes.
+
 2001-09-20  Jim Wilson  <wilson@redhat.com>
 
        * config/ia64/ia64.c (itanium_split_issue): Allow max 2 FP per cycle.
index 3298062..c3d11fe 100644 (file)
@@ -5190,7 +5190,8 @@ really_start_incremental_init (type)
            = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
 
          /* Detect non-empty initializations of zero-length arrays.  */
-         if (constructor_max_index == NULL_TREE)
+         if (constructor_max_index == NULL_TREE
+             && TYPE_SIZE (constructor_type))
            constructor_max_index = build_int_2 (-1, -1);
 
          constructor_index
@@ -5352,14 +5353,15 @@ push_init_level (implicit)
        {
          constructor_max_index
            = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
+
+         /* Detect non-empty initializations of zero-length arrays.  */
+         if (constructor_max_index == NULL_TREE
+             && TYPE_SIZE (constructor_type))
+           constructor_max_index = build_int_2 (-1, -1);
+
          constructor_index
            = convert (bitsizetype, 
                       TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
-
-         /* ??? For GCC 3.1, remove special case initialization of
-            zero-length array members from pop_init_level and set
-            constructor_max_index such that we get the normal
-            "excess elements" warning.  */
        }
       else
        constructor_index = bitsize_zero_node;
@@ -5438,19 +5440,9 @@ pop_init_level (implicit)
            constructor_type = NULL_TREE;
        }
       else
-       {
-         warning_init ("deprecated initialization of zero-length array");
-
-         /* We must be initializing the last member of a top-level struct.  */
-         if (TREE_CHAIN (constructor_fields) != NULL_TREE)
-           {
-             error_init ("initialization of zero-length array before end of structure");
-             /* Discard the initializer so that we do not abort later.  */
-             constructor_type = NULL_TREE;
-           }
-         else if (constructor_depth > 2)
-           error_init ("initialization of zero-length array inside a nested context");
-       }
+       /* Zero-length arrays are no longer special, so we should no longer
+          get here.  */
+       abort();
     }
 
   /* Warn when some struct elements are implicitly initialized to zero.  */
index 05a2e58..0834496 100644 (file)
@@ -1303,17 +1303,17 @@ of zero-length arrays, @code{sizeof} evaluates to zero.
 
 @item
 Flexible array members may only appear as the last member of a
-@code{struct} that is otherwise non-empty.  GCC currently allows
-zero-length arrays anywhere.  You may encounter problems, however,
-defining structures containing only a zero-length array.  Such usage
-is deprecated, and we recommend using zero-length arrays only in
-places in which flexible array members would be allowed.
+@code{struct} that is otherwise non-empty.
 @end itemize
 
 GCC versions before 3.0 allowed zero-length arrays to be statically
-initialized.  In addition to those cases that were useful, it also
-allowed initializations in situations that would corrupt later data.
-Non-empty initialization of zero-length arrays is now deprecated.
+initialized, as if they were flexible arrays.  In addition to those
+cases that were useful, it also allowed initializations in situations
+that would corrupt later data.  Non-empty initialization of zero-length
+arrays is now treated like any case where there are more initializer
+elements than the array holds, in that a suitable warning about "excess
+elements in array" is given, and the excess elements (all of them, in
+this case) are ignored.
 
 Instead GCC allows static initialization of flexible array members.
 This is equivalent to defining a new structure containing the original
index 3d0d93a..b61fc17 100644 (file)
@@ -4710,7 +4710,9 @@ store_constructor (exp, target, align, cleared, size)
       int need_to_clear;
       tree domain = TYPE_DOMAIN (type);
       tree elttype = TREE_TYPE (type);
-      int const_bounds_p = (host_integerp (TYPE_MIN_VALUE (domain), 0)
+      int const_bounds_p = (TYPE_MIN_VALUE (domain)
+                           && TYPE_MAX_VALUE (domain)
+                           && host_integerp (TYPE_MIN_VALUE (domain), 0)
                            && host_integerp (TYPE_MAX_VALUE (domain), 0));
       HOST_WIDE_INT minelt = 0;
       HOST_WIDE_INT maxelt = 0;
index 7f28c4c..16d4816 100644 (file)
@@ -1,3 +1,10 @@
+2001-09-20  DJ Delorie  <dj@redhat.com>
+
+       * gcc.dg/20000926-1.c: Update expected warning messages.
+       * gcc.dg/array-2.c: Likewise, and test for warnings too.
+       * gcc.dg/array-4.c: Likewise, and don't verify the zero-length
+       array.
+
 2001-09-18  Richard Sandiford  <rsandifo@redhat.com>
 
        * g++.dg/eh/registers1.C: New test case.
index 223714d..2f5ca10 100644 (file)
@@ -22,6 +22,6 @@ struct PLAYBOOK playbook  =
 {
   "BookName",
   {
-    { 1, "PName0" },
-  } /* { dg-warning "(deprecated initialization)|(near initialization)" "" } */
+    { 1, "PName0" }, /* { dg-warning "(excess elements)|(near initialization)" "" } */
+  }
 };
index dbf1733..06c753f 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-w" } */
+/* { dg-options "" } */
 
 /* Verify that we can't do things to get ourselves in trouble
    with GCC's initialized flexible array member extension.  */
@@ -10,4 +10,4 @@ struct g g1 = { { 0, { } } };
 struct g g2 = { { 0, { 1 } } }; /* { dg-error "(nested context)|(near initialization)" "nested" } */
 
 struct h { int x[0]; int y; };
-struct h h1 = { { 0 }, 1 }; /* { dg-error "(before end)|(near initialization)" "before end" } */
+struct h h1 = { { 0 }, 1 }; /* { dg-error "(excess elements)|(near initialization)" "before end" } */
index 52ad921..b3e4f6c 100644 (file)
@@ -12,7 +12,7 @@ struct g { int w; int x[0]; };
 
 static struct f f = { 4, { 0, 1, 2, 3 } };
 static int junk1[] = { -1, -1, -1, -1 };
-static struct g g = { 4, { 0, 1, 2, 3 } }; /* { dg-warning "(deprecated initialization)|(near initialization)" "" } */
+static struct g g = { 4, { 0, 1, 2, 3 } }; /* { dg-warning "(excess elements)|(near initialization)" "" } */
 static int junk2[] = { -1, -1, -1, -1 };
 
 int main()
@@ -21,8 +21,5 @@ int main()
   for (i = 0; i < f.w; ++i)
     if (f.x[i] != i)
       abort ();
-  for (i = 0; i < g.w; ++i)
-    if (g.x[i] != i)
-      abort ();
   exit(0);
 }