https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128349
--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Mikael Morin <[email protected]>: https://gcc.gnu.org/g:d471b9060100a62dd6a069de4edfa077f84a92fb commit r17-5879-gd471b9060100a62dd6a069de4edfa077f84a92fb Author: Mikael Morin <[email protected]> Date: Tue Nov 3 11:15:36 2026 +0100 fortran: Use polymorphic assignment to copy a class value to a temporary [PR128349] Propagate class information from the original variable when copying to a temporary, so that the copy assignment doesn't fall back to non-polymorphic assignment. In the example added to the testsuite here, the class container doesn't appear as prefix of the array reference, because of a temporary variable. As a result, in trans_scalar_class_assign, the call to gfc_get_class_from_expr is unable to guess any reference to the class container, and we fall back to non-polymorphic assignment. This change uses the class container reference that is already saved by the scalarizer, and copies it to the expression metadata. And in trans_scalar_class_assign, usage of that class container metadata is tried first if it is present, before falling back to the existing handling if not. PR fortran/128349 gcc/fortran/ChangeLog: * trans-expr.cc (gfc_conv_variable): Set class container expression from the one saved by the scalarizer. (trans_scalar_class_assign): Use previously set class container expression if it's available. gcc/testsuite/ChangeLog: * gfortran.dg/unlimited_polymorphic_34.f90: New test.
