From fe24d4852ee6dd41dbf9c5daa68f1a51903aa105 Mon Sep 17 00:00:00 2001 From: Olivier Hainque Date: Tue, 18 Jul 2006 13:07:28 +0000 Subject: tree.h (categorize_ctor_elements): Adjust prototype and add descriptive comment... * tree.h (categorize_ctor_elements): Adjust prototype and add descriptive comment, both in accordance with the interface change described below. * varasm.c (constructor_static_from_elts_p): New function. Whether a constructor node is a valid static constant initializer if all its elements are. (initializer_constant_valid_p) : Use it. * output.h: Declare it. * expr.c (categorize_ctor_elements_1): Return whether the constructor is a valid constant initializer instead of computing the number of non-constant elements. Use constructor_static_from_elts_p for this purpose. Replace the head comment with an indication that this is a helper for categorize_ctor_elements. (categorize_ctor_elements): Same interface change as for the _1 helper. Former head comment from this helper moved here, adjusted to account for the interface changes. (mostly_zeros_p): Adjust call to categorize_ctor_elements. (all_zeros_p): Likewise. * gimplify.c (gimplify_init_constructor): Decide whether we can make static versions of the constructor from the categorize_ctor_elements return value instead of the formerly computed number of non-constant elements. * gnat.dg/outer_agg_bitfield_constructor.adb: New test. * gnat.dg/nested_agg_bitfield_constructor.adb: New test. From-SVN: r115553 --- gcc/varasm.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'gcc/varasm.c') diff --git a/gcc/varasm.c b/gcc/varasm.c index 9dcc3b4..1f5f43a 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -3699,6 +3699,20 @@ output_addressed_constants (tree exp) } } +/* Whether a constructor CTOR is a valid static constant initializer if all + its elements are. This used to be internal to initializer_constant_valid_p + and has been exposed to let other functions like categorize_ctor_elements + evaluate the property while walking a constructor for other purposes. */ + +bool +constructor_static_from_elts_p (tree ctor) +{ + return (TREE_CONSTANT (ctor) + && (TREE_CODE (TREE_TYPE (ctor)) == UNION_TYPE + || TREE_CODE (TREE_TYPE (ctor)) == RECORD_TYPE) + && !VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (ctor))); +} + /* Return nonzero if VALUE is a valid constant-valued expression for use in initializing a static variable; one that can be an element of a "constant" initializer. @@ -3719,10 +3733,7 @@ initializer_constant_valid_p (tree value, tree endtype) switch (TREE_CODE (value)) { case CONSTRUCTOR: - if ((TREE_CODE (TREE_TYPE (value)) == UNION_TYPE - || TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE) - && TREE_CONSTANT (value) - && !VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (value))) + if (constructor_static_from_elts_p (value)) { unsigned HOST_WIDE_INT idx; tree elt; -- cgit v1.1