https://gcc.gnu.org/g:a5c69abf1384ec6163cd5e14146e8b3876e8b95c

commit r15-8642-ga5c69abf1384ec6163cd5e14146e8b3876e8b95c
Author: Andre Vehreschild <ve...@gcc.gnu.org>
Date:   Fri Mar 21 09:13:29 2025 +0100

    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:
---
 gcc/fortran/trans-array.cc                     |  2 +-
 gcc/testsuite/gfortran.dg/proc_ptr_comp_54.f90 | 30 ++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index e9eacf201283..960613167f72 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 000000000000..f5b7fa84955d
--- /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  <damian@archaeologic.codes>
+
+  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

Reply via email to