https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125722
--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jerry DeLisle <[email protected]>: https://gcc.gnu.org/g:02e6f6740ae069c9355dcb59d764235465f09a61 commit r17-3769-g02e6f6740ae069c9355dcb59d764235465f09a61 Author: Jerry DeLisle <[email protected]> Date: Thu Aug 27 08:59:06 2026 -0700 fortran: [PR125722] wrong code for an allocatable character array component A structure constructor copying an allocatable or deferred-length character array expression into an explicit-length allocatable character array component was lowered with gfc_duplicate_allocatable, which bitwise-copies the source at the destination element stride. When the source element length differs from the component length this copies the wrong bytes, so every element after the first is wrong. Copy such a component element by element with gfc_trans_string_copy, padding or truncating each element to the component length. PR fortran/125722 gcc/fortran/ChangeLog: * trans-expr.cc (gfc_char_elem_addr): New function. (gfc_trans_alloc_char_subarray_assign): New function. (gfc_trans_alloc_subarray_assign): Use it for an explicit-length allocatable character array component. gcc/testsuite/ChangeLog: * gfortran.dg/structure_constructor_22.f90: New test.
