diff options
author | Bernd Edlinger <bernd.edlinger@hotmail.de> | 2018-09-06 15:39:48 +0000 |
---|---|---|
committer | Jeff Law <law@gcc.gnu.org> | 2018-09-06 09:39:48 -0600 |
commit | 6d9001072d3ed5a82b8277426e6dd41a1c605990 (patch) | |
tree | f152a5f3a4863b32753531cb6e74a16358a52921 /gcc | |
parent | 6847c656b4153fbd0b552ac5051dc7b3ec44246a (diff) | |
download | gcc-6d9001072d3ed5a82b8277426e6dd41a1c605990.zip gcc-6d9001072d3ed5a82b8277426e6dd41a1c605990.tar.gz gcc-6d9001072d3ed5a82b8277426e6dd41a1c605990.tar.bz2 |
varasm.c (output_constructor_regular_field): Check TYPE_SIZE_UNIT of the init value.
* varasm.c (output_constructor_regular_field): Check TYPE_SIZE_UNIT of
the init value.
* c-common.c (complete_flexible_array_elts): New helper function.
* c-common.h (complete_flexible_array_elts): Declare.
* c-decl.c (finish_decl): Call complete_flexible_array_elts.
* decl.c (check_initializer): Call cp_complete_array_type.
From-SVN: r264147
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/c-family/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/c-family/c-common.c | 22 | ||||
-rw-r--r-- | gcc/c-family/c-common.h | 1 | ||||
-rw-r--r-- | gcc/c/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/c/c-decl.c | 2 | ||||
-rw-r--r-- | gcc/cp/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/cp/decl.c | 10 | ||||
-rw-r--r-- | gcc/varasm.c | 2 |
9 files changed, 55 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 19800f5..f8fedba 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2018-09-06 Bernd Edlinger <bernd.edlinger@hotmail.de> + + * varasm.c (output_constructor_regular_field): Check TYPE_SIZE_UNIT of + the init value. + 2018-09-06 Will Schmidt <will_schmidt@vnet.ibm.com> * config/rs6000/rs6000.c (rs6000_gimple_fold_builtin): Add support for diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 4129f24..75064a2 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,8 @@ +2018-09-06 Bernd Edlinger <bernd.edlinger@hotmail.de> + + * c-common.c (complete_flexible_array_elts): New helper function. + * c-common.h (complete_flexible_array_elts): Declare. + 2018-09-02 Bernd Edlinger <bernd.edlinger@hotmail.de> * c-common.c (braced_list_to_string): Remove eval parameter. diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 13ed65c..4bfb145 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -6425,6 +6425,28 @@ complete_array_type (tree *ptype, tree initial_value, bool do_default) return failure; } +/* INIT is an constructor of a structure with a flexible array member. + Complete the flexible array member with a domain based on it's value. */ +void +complete_flexible_array_elts (tree init) +{ + tree elt, type; + + if (init == NULL_TREE || TREE_CODE (init) != CONSTRUCTOR) + return; + + if (vec_safe_is_empty (CONSTRUCTOR_ELTS (init))) + return; + + elt = CONSTRUCTOR_ELTS (init)->last ().value; + type = TREE_TYPE (elt); + if (TREE_CODE (type) == ARRAY_TYPE + && TYPE_SIZE (type) == NULL_TREE) + complete_array_type (&TREE_TYPE (elt), elt, false); + else + complete_flexible_array_elts (elt); +} + /* Like c_mark_addressable but don't check register qualifier. */ void c_common_mark_addressable_vec (tree t) diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index cc168e2..9e86876 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -1038,6 +1038,7 @@ extern tree fold_offsetof (tree, tree = size_type_node, tree_code ctx = ERROR_MARK); extern int complete_array_type (tree *, tree, bool); +extern void complete_flexible_array_elts (tree); extern tree builtin_type_for_size (int, bool); diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 5c18f63..74d34b1 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,7 @@ +2018-09-06 Bernd Edlinger <bernd.edlinger@hotmail.de> + + * c-decl.c (finish_decl): Call complete_flexible_array_elts. + 2018-09-02 Bernd Edlinger <bernd.edlinger@hotmail.de> * c-decl.c (finish_decl): Call braced_list_to_string here ... diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index fd08d72..fdcfbde 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -5042,6 +5042,8 @@ finish_decl (tree decl, location_t init_loc, tree init, if (init && TREE_CODE (init) == CONSTRUCTOR) add_flexible_array_elts_to_size (decl, init); + complete_flexible_array_elts (DECL_INITIAL (decl)); + if (DECL_SIZE (decl) == NULL_TREE && TREE_TYPE (decl) != error_mark_node && COMPLETE_TYPE_P (TREE_TYPE (decl))) layout_decl (decl, 0); diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index d5879f8..42e70cd 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,7 @@ +2018-09-06 Bernd Edlinger <bernd.edlinger@hotmail.de> + + * decl.c (check_initializer): Call cp_complete_array_type. + 2018-09-05 Marek Polacek <polacek@redhat.com> PR c++/87109, wrong overload with ref-qualifiers. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 5962c19..50b60e8 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -6478,6 +6478,16 @@ check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups) init_code = store_init_value (decl, init, cleanups, flags); + if (DECL_INITIAL (decl) + && TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR + && !vec_safe_is_empty (CONSTRUCTOR_ELTS (DECL_INITIAL (decl)))) + { + tree elt = CONSTRUCTOR_ELTS (DECL_INITIAL (decl))->last ().value; + if (TREE_CODE (TREE_TYPE (elt)) == ARRAY_TYPE + && TYPE_SIZE (TREE_TYPE (elt)) == NULL_TREE) + cp_complete_array_type (&TREE_TYPE (elt), elt, false); + } + if (pedantic && TREE_CODE (type) == ARRAY_TYPE && DECL_INITIAL (decl) && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST diff --git a/gcc/varasm.c b/gcc/varasm.c index 2180da4..27d878f 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -5160,6 +5160,8 @@ output_constructor_regular_field (oc_local_state *local) 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); + tree size = TYPE_SIZE_UNIT (TREE_TYPE (local->val)); + gcc_checking_assert (compare_tree_int (size, fieldsize) == 0); } else fieldsize = tree_to_uhwi (DECL_SIZE_UNIT (local->field)); |