https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129026
--- Comment #2 from Mikael Morin <mikael at gcc dot gnu.org> --- (In reply to Mikael Morin from comment #0) > This is based on the sashiko review at [1]. (...) > [1]: > https://gcc.sashiko.dev/#/patchset/20261122194107.100343-1-morin- > mikael%40orange.fr?part=3 The original patch for this was: https://gcc.gnu.org/pipermail/gcc-patches/2026-November/740302.html I'm pasting below the AI-generated content from [1]. While guarding gfc_class_data_get here in gfc_set_descriptor_from_scalar_class (in gcc/fortran/trans-descriptor.cc) fixes the pre-call descriptor initialization in gfc_conv_class_to_class (in gcc/fortran/trans-expr.cc), the symmetric post-call copyback branch for e->rank == 0 in gfc_conv_class_to_class still calls gfc_class_data_get (parmse->expr) unconditionally: if (copyback) { if (full_array) { if (e->rank == 0) { tmp = gfc_class_data_get (parmse->expr); gfc_add_modify (&parmse->post, tmp, fold_convert (TREE_TYPE (tmp), gfc_conv_descriptor_data_get (ctree))); } When an allocatable scalar polymorphic coarray (e.g. class(t0), allocatable :: a[:]) is passed to an allocatable assumed-rank dummy argument with non-INTENT(IN) (e.g. class(t0), allocatable :: a(..)), gfc_conv_procedure_call lowers parmse.expr to a._data.data (of pointer-to-t0 type rather than a class container) and invokes gfc_conv_class_to_class with copyback = true and full_array = true. In the post-call copyback path, gfc_class_data_get (parmse->expr) dereferences parmse->expr to the declared derived type and looks up CLASS_DATA_FIELD (field 0) in TYPE_FIELDS. If the declared type has no components (as in assumed_rank_26.f90), gfc_advance_chain returns NULL_TREE and TREE_TYPE (data) crashes with an ICE (segmentation fault). If the declared type has components, gfc_class_data_get builds a COMPONENT_REF to the first user component and the copyback assignment overwrites that user component with the descriptor data pointer instead of updating the coarray's data pointer (wrong-code or a GIMPLE type verification ICE). The e->rank == 0 copyback branch in gfc_conv_class_to_class also needs to handle non-class-container parmse->expr expressions (or recover the underlying descriptor data field) rather than calling gfc_class_data_get unconditionally.
