> Note that you'll get ICEs whenever TYPE_CANONICAL of some
> aggregate type is NULL (thus, TYPE_STRUCTURAL_EQUALITY), so this
> seems inherently fragile (similar to using TYPE_CANONICAL == TYPE_CANONICAL
> here, we'd break the TYPE_STRUCTURAL_EQUALITY case again).
Could you elaborate? The patch was successfully regtested.
> I think that either the original fix needs to be re-thought or we need to
> pass the base FIELD_DECL to build_ref_for_model.
> That is, why not stop extracting the component-refs in
>
> do {
> tree field = TREE_OPERAND (expr, 1);
> tree cr_offset = component_ref_field_offset (expr);
> gcc_assert (cr_offset && host_integerp (cr_offset, 1));
>
> offset -= TREE_INT_CST_LOW (cr_offset) * BITS_PER_UNIT;
> offset -= TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (field));
>
> VEC_safe_push (tree, stack, cr_stack, expr);
>
> expr = TREE_OPERAND (expr, 0);
> type = TREE_TYPE (expr);
> } while (TREE_CODE (expr) == COMPONENT_REF);
>
> when expr == base?
Because SRA uses the model of the LHS to build the access on the RHS, so this
kind of equalitty condition cannot work.
> The whole point of course was to never need something like
> build_ref_for_model given that we have MEM_REFs.
MEM_REF is nice, but SRA should stop rewriting component accesses that it
doesn't scalarize, this is waste of time and memory, and introduces bugs.
--
Eric Botcazou