From: Andre Vehreschild Date: Fri, 21 Mar 2025 08:13:29 +0000 (+0100) Subject: Fortran: Fix freeing procedure pointer components [PR119380] X-Git-Tag: basepoints/gcc-16~911 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a5c69abf1384ec6163cd5e14146e8b3876e8b95c;p=thirdparty%2Fgcc.git Fortran: Fix freeing procedure pointer components [PR119380] PR fortran/119380 gcc/fortran/ChangeLog: * trans-array.cc (structure_alloc_comps): Prevent freeing of procedure pointer components. gcc/testsuite/ChangeLog: * gfortran.dg/proc_ptr_comp_54.f90: New test. --- diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc index e9eacf20128..960613167f7 100644 --- a/gcc/fortran/trans-array.cc +++ b/gcc/fortran/trans-array.cc @@ -10109,7 +10109,7 @@ structure_alloc_comps (gfc_symbol * der_type, tree decl, tree dest, else { attr = &c->attr; - if (attr->pointer) + if (attr->pointer || attr->proc_pointer) continue; } diff --git a/gcc/testsuite/gfortran.dg/proc_ptr_comp_54.f90 b/gcc/testsuite/gfortran.dg/proc_ptr_comp_54.f90 new file mode 100644 index 00000000000..f5b7fa84955 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/proc_ptr_comp_54.f90 @@ -0,0 +1,30 @@ +!{ dg-do run } + +! Do not free procedure pointer components. +! Contributed by Damian Rouson + + implicit none + + type foo_t + integer, allocatable :: i_ + procedure(f), pointer, nopass :: f_ + procedure(c), pointer, nopass :: c_ + end type + + class(foo_t), allocatable :: ff + + associate(foo => foo_t(1,f)) + end associate + +contains + + function f() + logical, allocatable :: f + f = .true. + end function + + function c() + class(foo_t), allocatable :: c + allocate(c) + end function +end