On Mon, Jan 04, 2021 at 07:22:58PM -0500, David Malcolm via Gcc-patches wrote:
> --- a/gcc/analyzer/store.cc
> +++ b/gcc/analyzer/store.cc
> @@ -524,10 +524,27 @@ binding_map::apply_ctor_to_region (const region 
> *parent_reg, tree ctor,
>    unsigned ix;
>    tree index;
>    tree val;
> +  tree parent_type = parent_reg->get_type ();
> +  tree field;
> +  if (TREE_CODE (parent_type) == RECORD_TYPE)
> +    field = TYPE_FIELDS (parent_type);
> +  else
> +    field = NULL_TREE;
>    FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), ix, index, val)
>      {
>        if (!index)
> -     index = build_int_cst (integer_type_node, ix);
> +     {
> +       /* If index is NULL, then iterate through the fields for
> +          a RECORD_TYPE, or use an INTEGER_CST otherwise.
> +          Compare with similar logic in output_constructor.  */
> +       if (field)
> +         {
> +           index = field;
> +           field = DECL_CHAIN (field);
> +         }

The TYPE_FIELDS chain doesn't contain only FIELD_DECLs, can contain other
decls (FUNCTION_DECLs, USING_DECLs, TYPE_DECLs, ...).
So this should be really skipping chain elts other than FIELD_DECLs.
E.g. C++ FE has next_initializable_field function for that, unfortunately
the middle-end doesn't.

        Jakub

Reply via email to