aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorDJ Delorie <dj@redhat.com>2001-09-20 20:27:59 -0400
committerDJ Delorie <dj@gcc.gnu.org>2001-09-20 20:27:59 -0400
commite7b6a0ee34197334228ed9185ebaf84d5b975110 (patch)
tree367fe25e25603ec8574df8960ea2e634f886da63 /gcc
parentf5aee6316d591598ac8574b47b79fa35e10bca2c (diff)
downloadgcc-e7b6a0ee34197334228ed9185ebaf84d5b975110.zip
gcc-e7b6a0ee34197334228ed9185ebaf84d5b975110.tar.gz
gcc-e7b6a0ee34197334228ed9185ebaf84d5b975110.tar.bz2
c-typeck.c (really_start_incremental_init): Discriminate between zero-length arrays and flexible arrays.
* 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. * 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. From-SVN: r45714
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog10
-rw-r--r--gcc/c-typeck.c30
-rw-r--r--gcc/doc/extend.texi16
-rw-r--r--gcc/expr.c4
-rw-r--r--gcc/testsuite/ChangeLog7
-rw-r--r--gcc/testsuite/gcc.dg/20000926-1.c4
-rw-r--r--gcc/testsuite/gcc.dg/array-2.c4
-rw-r--r--gcc/testsuite/gcc.dg/array-4.c5
8 files changed, 44 insertions, 36 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index c0190fc..1419033 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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.
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index 3298062..c3d11fe 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -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. */
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 05a2e58..0834496 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -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
diff --git a/gcc/expr.c b/gcc/expr.c
index 3d0d93a..b61fc17 100644
--- a/gcc/expr.c
+++ b/gcc/expr.c
@@ -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;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 7f28c4c..16d4816 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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.
diff --git a/gcc/testsuite/gcc.dg/20000926-1.c b/gcc/testsuite/gcc.dg/20000926-1.c
index 223714d..2f5ca10 100644
--- a/gcc/testsuite/gcc.dg/20000926-1.c
+++ b/gcc/testsuite/gcc.dg/20000926-1.c
@@ -22,6 +22,6 @@ struct PLAYBOOK playbook =
{
"BookName",
{
- { 1, "PName0" },
- } /* { dg-warning "(deprecated initialization)|(near initialization)" "" } */
+ { 1, "PName0" }, /* { dg-warning "(excess elements)|(near initialization)" "" } */
+ }
};
diff --git a/gcc/testsuite/gcc.dg/array-2.c b/gcc/testsuite/gcc.dg/array-2.c
index dbf1733..06c753f 100644
--- a/gcc/testsuite/gcc.dg/array-2.c
+++ b/gcc/testsuite/gcc.dg/array-2.c
@@ -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" } */
diff --git a/gcc/testsuite/gcc.dg/array-4.c b/gcc/testsuite/gcc.dg/array-4.c
index 52ad921..b3e4f6c 100644
--- a/gcc/testsuite/gcc.dg/array-4.c
+++ b/gcc/testsuite/gcc.dg/array-4.c
@@ -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);
}