diff options
author | hainque <hainque@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-07-18 13:07:28 +0000 |
---|---|---|
committer | hainque <hainque@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-07-18 13:07:28 +0000 |
commit | 20169a6424f72bb0852b222ccd726793317904d1 (patch) | |
tree | 4065694fdb2ca6a3a4f7e10356db5f8774473035 /gcc/expr.c | |
parent | 3e427a9c6d314d755d819b33eaede97c3b227127 (diff) | |
download | gcc-20169a6424f72bb0852b222ccd726793317904d1.tar.gz |
* 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) <CONSTRUCTOR value>: 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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@115553 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/expr.c')
-rw-r--r-- | gcc/expr.c | 72 |
1 files changed, 43 insertions, 29 deletions
diff --git a/gcc/expr.c b/gcc/expr.c index e46e3e787bd..48ec0ef6f67 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -4531,28 +4531,24 @@ store_expr (tree exp, rtx target, int call_param_p) return NULL_RTX; } -/* Examine CTOR to discover: - * how many scalar fields are set to nonzero values, - and place it in *P_NZ_ELTS; - * how many scalar fields are set to non-constant values, - and place it in *P_NC_ELTS; and - * how many scalar fields in total are in CTOR, - and place it in *P_ELT_COUNT. - * if a type is a union, and the initializer from the constructor - is not the largest element in the union, then set *p_must_clear. */ +/* Helper for categorize_ctor_elements. Identical interface. */ -static void +static bool categorize_ctor_elements_1 (tree ctor, HOST_WIDE_INT *p_nz_elts, - HOST_WIDE_INT *p_nc_elts, HOST_WIDE_INT *p_elt_count, bool *p_must_clear) { unsigned HOST_WIDE_INT idx; - HOST_WIDE_INT nz_elts, nc_elts, elt_count; + HOST_WIDE_INT nz_elts, elt_count; tree value, purpose; + /* Whether CTOR is a valid constant initializer, in accordance with what + initializer_constant_valid_p does. If inferred from the constructor + elements, true until proven otherwise. */ + bool const_from_elts_p = constructor_static_from_elts_p (ctor); + bool const_p = const_from_elts_p ? true : TREE_STATIC (ctor); + nz_elts = 0; - nc_elts = 0; elt_count = 0; FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), idx, purpose, value) @@ -4574,11 +4570,16 @@ categorize_ctor_elements_1 (tree ctor, HOST_WIDE_INT *p_nz_elts, { case CONSTRUCTOR: { - HOST_WIDE_INT nz = 0, nc = 0, ic = 0; - categorize_ctor_elements_1 (value, &nz, &nc, &ic, p_must_clear); + HOST_WIDE_INT nz = 0, ic = 0; + + bool const_elt_p + = categorize_ctor_elements_1 (value, &nz, &ic, p_must_clear); + nz_elts += mult * nz; - nc_elts += mult * nc; - elt_count += mult * ic; + elt_count += mult * ic; + + if (const_from_elts_p && const_p) + const_p = const_elt_p; } break; @@ -4617,8 +4618,10 @@ categorize_ctor_elements_1 (tree ctor, HOST_WIDE_INT *p_nz_elts, default: nz_elts += mult; elt_count += mult; - if (!initializer_constant_valid_p (value, TREE_TYPE (value))) - nc_elts += mult; + + if (const_from_elts_p && const_p) + const_p = initializer_constant_valid_p (value, TREE_TYPE (value)) + != NULL_TREE; break; } } @@ -4660,22 +4663,33 @@ categorize_ctor_elements_1 (tree ctor, HOST_WIDE_INT *p_nz_elts, } *p_nz_elts += nz_elts; - *p_nc_elts += nc_elts; *p_elt_count += elt_count; + + return const_p; } -void +/* Examine CTOR to discover: + * how many scalar fields are set to nonzero values, + and place it in *P_NZ_ELTS; + * how many scalar fields in total are in CTOR, + and place it in *P_ELT_COUNT. + * if a type is a union, and the initializer from the constructor + is not the largest element in the union, then set *p_must_clear. + + Return whether or not CTOR is a valid static constant initializer, the same + as "initializer_constant_valid_p (CTOR, TREE_TYPE (CTOR)) != 0". */ + +bool categorize_ctor_elements (tree ctor, HOST_WIDE_INT *p_nz_elts, - HOST_WIDE_INT *p_nc_elts, HOST_WIDE_INT *p_elt_count, bool *p_must_clear) { *p_nz_elts = 0; - *p_nc_elts = 0; *p_elt_count = 0; *p_must_clear = false; - categorize_ctor_elements_1 (ctor, p_nz_elts, p_nc_elts, p_elt_count, - p_must_clear); + + return + categorize_ctor_elements_1 (ctor, p_nz_elts, p_elt_count, p_must_clear); } /* Count the number of scalars in TYPE. Return -1 on overflow or @@ -4777,10 +4791,10 @@ mostly_zeros_p (tree exp) if (TREE_CODE (exp) == CONSTRUCTOR) { - HOST_WIDE_INT nz_elts, nc_elts, count, elts; + HOST_WIDE_INT nz_elts, count, elts; bool must_clear; - categorize_ctor_elements (exp, &nz_elts, &nc_elts, &count, &must_clear); + categorize_ctor_elements (exp, &nz_elts, &count, &must_clear); if (must_clear) return 1; @@ -4800,10 +4814,10 @@ all_zeros_p (tree exp) if (TREE_CODE (exp) == CONSTRUCTOR) { - HOST_WIDE_INT nz_elts, nc_elts, count; + HOST_WIDE_INT nz_elts, count; bool must_clear; - categorize_ctor_elements (exp, &nz_elts, &nc_elts, &count, &must_clear); + categorize_ctor_elements (exp, &nz_elts, &count, &must_clear); return nz_elts == 0; } |