https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125534
--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The releases/gcc-16 branch has been updated by Jerry DeLisle <[email protected]>: https://gcc.gnu.org/g:5598624357ff22cdf28769550049732f3b7bb000 commit r16-9102-g5598624357ff22cdf28769550049732f3b7bb000 Author: Jerry DeLisle <[email protected]> Date: Fri Jun 5 13:19:58 2026 -0700 fortran: ALLOCATE of parameterized derived-type array initializes only first element gfc_trans_allocate passed expr->rank to gfc_allocate_pdt_comp and gfc_deallocate_pdt_comp for array allocations of parameterized derived types. For an allocate-shape-spec expression (e.g. "allocate(a(n))"), expr->rank is 0 even though the symbol is an array; the rank is carried on the symbol rather than on the allocate expression. With rank 0 the loop that initialises each element's allocatable components ran zero times, so only element zero was initialised. Subsequent accesses to elements 1..N-1 used garbage pointers and crashed. Fix: when se.expr is a GFC array descriptor, take the rank from the descriptor via GFC_TYPE_ARRAY_RANK instead of from expr->rank. Apply the same correction to the CLASS path and to the matching deallocate calls in gfc_trans_deallocate. Assisted-by: Claude Sonnet 4.6 PR fortran/125534 gcc/fortran/ChangeLog: * trans-stmt.cc (gfc_trans_allocate): Use GFC_TYPE_ARRAY_RANK from the GFC descriptor type when se.expr is a descriptor, rather than expr->rank, for the rank passed to gfc_allocate_pdt_comp. Apply the same fix to the CLASS path. (gfc_trans_deallocate): Likewise for gfc_deallocate_pdt_comp. gcc/testsuite/ChangeLog: * gfortran.dg/pdt_array_alloc_1.f90: New test. (cherry picked from commit 5f12403a8ff7d2e8a62703aa33496b514cf6af3e)
