]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: fix issue with multiple references of a procedure pointer [PR97245]
authorHarald Anlauf <anlauf@gmx.de>
Fri, 3 Nov 2023 18:41:54 +0000 (19:41 +0100)
committerHarald Anlauf <anlauf@gmx.de>
Sat, 4 Nov 2023 14:45:15 +0000 (15:45 +0100)
gcc/fortran/ChangeLog:

PR fortran/97245
* match.cc (gfc_match_call): If a procedure pointer has already been
resolved, do not create a new symbol in a procedure reference of
the same name shadowing the first one if it is host-associated.

gcc/testsuite/ChangeLog:

PR fortran/97245
* gfortran.dg/proc_ptr_53.f90: New test.

(cherry picked from commit 5340f48b7639fcc874f64aac214f9ef9ae43d43e)

gcc/fortran/match.cc
gcc/testsuite/gfortran.dg/proc_ptr_53.f90 [new file with mode: 0644]

index 5eb6d0e1c1dbfffd9fb473f5a259171dc8268bb8..dea246a9d0b218581929f3df193615da9918533d 100644 (file)
@@ -5062,6 +5062,7 @@ gfc_match_call (void)
      right association is made.  They are thrown out in resolution.)
      ...  */
   if (!sym->attr.generic
+       && !sym->attr.proc_pointer
        && !sym->attr.subroutine
        && !sym->attr.function)
     {
diff --git a/gcc/testsuite/gfortran.dg/proc_ptr_53.f90 b/gcc/testsuite/gfortran.dg/proc_ptr_53.f90
new file mode 100644 (file)
index 0000000..29dd08d
--- /dev/null
@@ -0,0 +1,35 @@
+! { dg-do compile }
+! PR fortran/97245 - ASSOCIATED intrinsic did not recognize a
+!                    pointer variable the second time it is used
+
+MODULE formulaciones
+  IMPLICIT NONE
+
+  ABSTRACT INTERFACE
+     SUBROUTINE proc_void()
+     END SUBROUTINE proc_void
+  end INTERFACE
+
+  PROCEDURE(proc_void), POINTER :: pADJSensib => NULL()
+
+CONTAINS
+
+  subroutine calculo()
+    PROCEDURE(proc_void), POINTER :: otherprocptr => NULL()
+
+    IF (associated(pADJSensib)) THEN
+       CALL pADJSensib ()
+    ENDIF
+    IF (associated(pADJSensib)) THEN    ! this was erroneously rejected
+       CALL pADJSensib ()
+    END IF
+
+    IF (associated(otherprocptr)) THEN
+       CALL otherprocptr ()
+    ENDIF
+    IF (associated(otherprocptr)) THEN
+       CALL otherprocptr ()
+    END IF
+  end subroutine calculo
+
+END MODULE formulaciones