From 1ca323b8d58846d0890a8595ba9fc7bc7eee8fdd Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Fri, 3 Nov 2023 19:41:54 +0100
Subject: [PATCH] Fortran: fix issue with multiple references of a procedure
pointer [PR97245]
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.
---
gcc/fortran/match.cc | 1 +
gcc/testsuite/gfortran.dg/proc_ptr_53.f90 | 35 +++++++++++++++++++++++
2 files changed, 36 insertions(+)
create mode 100644 gcc/testsuite/gfortran.dg/proc_ptr_53.f90
@@ -5064,6 +5064,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)
{
new file mode 100644
@@ -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
--
2.35.3