https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128682
--- Comment #8 from Mikael Morin <mikael at gcc dot gnu.org> ---
(In reply to Steve Kargl from comment #4)
>
> The ICE is coming from an assert in gfc_get_expr_charlen() at
> trans-expr.cc:2295
>
> gcc_assert (e->expr_type == EXPR_VARIABLE
> && e->ts.type == BT_CHARACTER);
>
> The comment above the function is
>
> /* Get the character length of an expression, looking through gfc_refs
> if necessary. */
>
>
> The untested fix is to do
>
> gcc_assert (e->ts.type == BT_CHARACTER);
>
> or
>
> gcc_assert ((e->expr_type == EXPR_VARIABLE || e->expr_type ==
> EXPR_FUNCTION)
> && e->ts.type == BT_CHARACTER);
No, the function walks e->ref, so e is supposed to be a variable.
The problem happens because we look at the variable through TRANSPOSE.
In gfc_conv_expr_descriptor, all non-TRANSPOSE cases are handled by this:
8513 else if (expr->expr_type == EXPR_FUNCTION && !transposed_dims (ss))
8514 {
8515 desc = info->descriptor;
8516 se->string_length = ss_info->string_length;
8517 }
So what remains are variables, and TRANSPOSE functions.
In the case of TRANSPOSE, the function gfc_get_expr_charlen could be called
with gfc_get_noncopying_intrinsic_argument (expr) as argument instead of just
expr.