Le 15/11/2026 à 04:14, Jerry DeLisle a écrit :
See attached patch. For w = z, with w an allocatable TYPE(t) array and z a CLASS(t) array, reallocation on assignment took the element size from the type node of z, which is the class container (72 bytes at rank 1), not t. A t larger than that overflowed w, and the new test segfaults on trunk; a smaller t was over-allocated and w got the container size as its span. The variable and expr have the same declared type here (Table 10.8), so the patch takes the element size from the declared type of z, as is already done when w is CLASS too.The fix is in gfc_alloc_allocatable_for_assignment in trans-array.cc; the rest is the new test. Regression tested on x86_64. OK for mainline? Regards, Jerry --- fortran: [PR128736] Heap overflow assigning CLASS array to TYPE array When a CLASS array was assigned to an allocatable array of its declared type, reallocation on assignment sized each element of the variable as the class container instead of the declared type. A type larger than the container overflowed the new array, and a smaller one was over-allocated and given the wrong span. Take the element size from the declared type of the CLASS expression. Assisted-by: Claude Opus 5.5 PR fortran/128736 gcc/fortran/ChangeLog: * trans-array.cc (gfc_alloc_allocatable_for_assignment): Take the element size of a variable that is not polymorphic from the declared type of a polymorphic expression. gcc/testsuite/ChangeLog: * gfortran.dg/pr128736.f90: New test.
OK.
