diff options
author | Richard Henderson <rth@redhat.com> | 2001-01-04 21:58:23 -0800 |
---|---|---|
committer | Richard Henderson <rth@gcc.gnu.org> | 2001-01-04 21:58:23 -0800 |
commit | ffc5c6a98441d8e1abe6cdc0d2a93591e21191d7 (patch) | |
tree | f0375afbbd6220caa4aacf6320495224ac911480 /gcc/c-decl.c | |
parent | 00de56c7d0e654b52c23e789dbe3cc32d361a527 (diff) | |
download | gcc-ffc5c6a98441d8e1abe6cdc0d2a93591e21191d7.zip gcc-ffc5c6a98441d8e1abe6cdc0d2a93591e21191d7.tar.gz gcc-ffc5c6a98441d8e1abe6cdc0d2a93591e21191d7.tar.bz2 |
c-decl.c (finish_struct): Detect flexible array members used in an inappropriate context.
* c-decl.c (finish_struct): Detect flexible array members
used in an inappropriate context.
* c-typeck.c (really_start_incremental_init): Special case
constructor_max_index for zero length arrays.
(pop_init_level): Allow initialization of flexible array
members. Deprecate initialization of zero length arrays.
Don't issue missing initializer warning for flexible array
members or zero length arrays.
(process_init_element): Don't dereference null DECL_SIZE.
* varasm.c (array_size_for_constructor): Return a HOST_WIDE_INT.
Don't abort for empty constructors. Use size_binop
(output_constructor): Add commentary regarding zero length
array futures. Abort if we try to initialize an array of
unspecified length with a non-empty constructor in the middle
of a structure.
* extend.texi (Zero Length): Update and clarify documentation
on static initialization.
From-SVN: r38705
Diffstat (limited to 'gcc/c-decl.c')
-rw-r--r-- | gcc/c-decl.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/gcc/c-decl.c b/gcc/c-decl.c index c813d3e..0a94db0 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -5200,6 +5200,7 @@ finish_struct (t, fieldlist, attributes) { register tree x; int toplevel = global_binding_level == current_binding_level; + int saw_named_field; /* If this type was previously laid out as a forward reference, make sure we lay it out again. */ @@ -5238,6 +5239,7 @@ finish_struct (t, fieldlist, attributes) Store 0 there, except for ": 0" fields (so we can find them and delete them, below). */ + saw_named_field = 0; for (x = fieldlist; x; x = TREE_CHAIN (x)) { DECL_CONTEXT (x) = t; @@ -5371,6 +5373,22 @@ finish_struct (t, fieldlist, attributes) } DECL_INITIAL (x) = 0; + + /* Detect flexible array member in an invalid context. */ + if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE + && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE + && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE + && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE) + { + if (TREE_CODE (t) == UNION_TYPE) + error_with_decl (x, "flexible array member in union"); + else if (TREE_CHAIN (x) != NULL_TREE) + error_with_decl (x, "flexible array member not at end of struct"); + else if (! saw_named_field) + error_with_decl (x, "flexible array member in otherwise empty struct"); + } + if (DECL_NAME (x)) + saw_named_field = 1; } /* Delete all duplicate fields from the fieldlist */ @@ -5416,8 +5434,8 @@ finish_struct (t, fieldlist, attributes) fieldlistp = &TREE_CHAIN (*fieldlistp); } - /* Now we have the truly final field list. - Store it in this type and in the variants. */ + /* Now we have the truly final field list. + Store it in this type and in the variants. */ TYPE_FIELDS (t) = fieldlist; |