Mostly Paul's patch with some edits by myself. Regression tested and pushed.
Thanks Paul for your work. The master branch has been updated by Jerry DeLisle <[email protected]>: https://gcc.gnu.org/g:95dbc32189ab0433283f337b4b490bfcec0bd475 commit r17-2071-g95dbc32189ab0433283f337b4b490bfcec0bd475 Author: Paul Thomas <[email protected]> Date: Wed Jul 1 17:14:25 2026 +0100 Fortran: Fix asan problems with PDT testcases [PR121972] Co-authored-by: Jerry DeLisle <[email protected]> PR fortran/121972 gcc/fortran * expr.cc (has_parameterized_comps): Return false if the DT is neither a pdt_type nor has PDT components. Correct the logic for a PDT component. * trans-expr.cc (alloc_scalar_allocatable_for_assignment): Use calloc for types with paramterized components as well as those with allocatable components. * trans-stmt.cc (gfc_trans_allocate): Merge the allocation of parameterized components of PDTs and class PDTs into one block If an allocate type_spec is present that has allocatable comps where the class declared type does not, nullify the allocatable components. gcc/testsuite/ * gfortran.dg/asan/pdt_46.f03: Copy of original with tree dump for counts of frees, mallocs and callocs removed. * gfortran.dg/asan/pdt_77.f03: Ditto. * gfortran.dg/pdt_46.f03: Calloc count added, corresponding to reduction in mallocs.. * gfortran.dg/pdt_50.f03: Ditto.
