]> 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>
Thu, 3 Apr 2025 09:38:33 +0000 (11:38 +0200)
Backported from gcc-15.

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 c1c2b933b27976d34e150e3d6b5265e24b2fdf38..50286e4120e6ebfa1de269f84b7745e23de6b0ef 100644 (file)
@@ -9694,13 +9694,13 @@ structure_alloc_comps (gfc_symbol * der_type, tree decl, tree dest,
          if (c->ts.type == BT_CLASS)
            {
              attr = &CLASS_DATA (c)->attr;
-             if (attr->class_pointer)
+             if (attr->class_pointer || c->attr.proc_pointer)
                continue;
            }
          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..73abc59
--- /dev/null
@@ -0,0 +1,30 @@
+!{ dg-do run }
+
+! Check that components of procedure pointer aren't freeed.
+! 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