]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: Fix freeing procedure pointer components [PR119380]
authorAndre Vehreschild <vehre@gcc.gnu.org>
Fri, 21 Mar 2025 08:13:29 +0000 (09:13 +0100)
committerAndre Vehreschild <vehre@gcc.gnu.org>
Fri, 21 Mar 2025 12:31:55 +0000 (13:31 +0100)
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.

gcc/fortran/trans-array.cc
gcc/testsuite/gfortran.dg/proc_ptr_comp_54.f90 [new file with mode: 0644]

index e9eacf2012836f5eb6b30fc8e0065203bab05c7d..960613167f723f684dbe7a8883c1b33d3af545a6 100644 (file)
@@ -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 (file)
index 0000000..f5b7fa8
--- /dev/null
@@ -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