diff options
author | Martin Sebor <msebor@redhat.com> | 2015-12-15 21:04:08 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2015-12-15 14:04:08 -0700 |
commit | 7e9a3ad30076ad8a91b8f61352aa98b417191ed5 (patch) | |
tree | 50f9efd8d71500ea8804646ff802d54fe104ece9 /gcc/varasm.c | |
parent | 1f0659546bcf5b95c3263cdc73149f6c2a05ebe1 (diff) | |
download | gcc-7e9a3ad30076ad8a91b8f61352aa98b417191ed5.zip gcc-7e9a3ad30076ad8a91b8f61352aa98b417191ed5.tar.gz gcc-7e9a3ad30076ad8a91b8f61352aa98b417191ed5.tar.bz2 |
struct-layout-1_generate.c: Avoid generating further fields after the first flexible array member.
gcc/testsuite/ChangeLog:
2015-12-15 Martin Sebor <msebor@redhat.com>
c++/42121
c++/68478
c++/68613
c++/68689
c++/68710
* g++.dg/compat/struct-layout-1_generate.c: Avoid generating
further fields after the first flexible array member.
* g++.dg/ext/flexary2.C: Expect a sole flexible array member
to be rejected. Add a test case exercising zero-length array.
* g++.dg/ext/flexary3.C: Expect a sole flexible array member
to be rejected.
* g++.dg/ext/flexary.h: New file.
* g++.dg/ext/flexary4.C: New file.
* g++.dg/ext/flexary5.C: New file.
* g++.dg/ext/flexary6.C: New file.
* g++.dg/ext/flexary7.C: New file.
* g++.dg/ext/flexary8.C: New file.
* g++.dg/other/dump-ada-spec-2.C: Adjust to reflect flexible
array members.
* g++.dg/parse/pr43765.C: Add a member to make a struct with
a flexible array member valid. Adjust expected error message.
* g++.dg/torture/pr64280.C: Expect a sole flexible array member
to be rejected.
* g++.dg/torture/pr64312.C: Add a member to make a struct with
a flexible array member valid.
* g++.dg/ubsan/object-size-1.C: Adjust expected diagnostic.
gcc/cp/ChangeLog:
2015-12-15 Martin Sebor <msebor@redhat.com>
c++/42121
c++/68478
c++/68613
c++/68689
c++/68710
* class.c (walk_subobject_offsets): Avoid assuming type domain
is non-null or has an upper bound.
(layout_class_type): Include type size in error message.
(flexmems_t): New type.
(field_nonempty_p, find_flexarrays, diagnose_flexarrays)
(check_flexarrays): New functions.
(finish_struct_1): Call check_flexarrays.
* decl.c (compute_array_index_type): Distinguish flexible array
members from zero-length arrays.
(grokdeclarator): Reject flexible array members in unions. Avoid
rejecting members of incomplete types that are flexible array members.
* error.c (dump_type_suffix): Handle flexible array members with null
upper bound.
* init.c (perform_member_init): Same.
* pt.c (instantiate_class_template_1): Allow flexible array members.
(tsubst): Handle flexible array members with null upper bound.
* typeck2.c (digest_init_r): Warn for initialization of flexible
array members.
(process_init_constructor_record): Handle flexible array members.
gcc/ChangeLog:
2015-12-15 Martin Sebor <msebor@redhat.com>
c++/42121
* tree-chkp.c (chkp_find_bound_slots_1): Handle flexible array
members.
* tree.c (type_contains_placeholder_1): Avoid assuming type has
a non-null domain or an upper bound to handle flexible array
members.
* varasm.c (output_constructor_regular_field): Same.
(output_constructor): Set min_index to integer_zero_node rather
than null when a type has no domain to avoid crashing later.
From-SVN: r231665
Diffstat (limited to 'gcc/varasm.c')
-rw-r--r-- | gcc/varasm.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/gcc/varasm.c b/gcc/varasm.c index c4c55e7..643d682 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -4974,13 +4974,15 @@ output_constructor_regular_field (oc_local_state *local) but we cannot do this until the deprecated support for initializing zero-length array members is removed. */ if (TREE_CODE (TREE_TYPE (local->field)) == ARRAY_TYPE - && TYPE_DOMAIN (TREE_TYPE (local->field)) - && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (local->field)))) + && (!TYPE_DOMAIN (TREE_TYPE (local->field)) + || !TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (local->field))))) { fieldsize = array_size_for_constructor (local->val); - /* Given a non-empty initialization, this field had - better be last. */ - gcc_assert (!fieldsize || !DECL_CHAIN (local->field)); + /* Given a non-empty initialization, this field had better + be last. Given a flexible array member, the next field + on the chain is a TYPE_DECL of the enclosing struct. */ + const_tree next = DECL_CHAIN (local->field); + gcc_assert (!fieldsize || !next || TREE_CODE (next) != FIELD_DECL); } else fieldsize = tree_to_uhwi (DECL_SIZE_UNIT (local->field)); @@ -5196,7 +5198,7 @@ output_constructor (tree exp, unsigned HOST_WIDE_INT size, unsigned int align, if (TREE_CODE (local.type) == ARRAY_TYPE && TYPE_DOMAIN (local.type)) local.min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (local.type)); else - local.min_index = NULL_TREE; + local.min_index = integer_zero_node; local.total_bytes = 0; local.byte_buffer_in_use = outer != NULL; |