diff options
Diffstat (limited to 'gcc/expr.c')
| -rw-r--r-- | gcc/expr.c | 72 |
1 files changed, 43 insertions, 29 deletions
@@ -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; } |
