From: Harald Anlauf <anlauf@gmx.de>
To: fortran <fortran@gcc.gnu.org>, gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH] Fortran: fix issue with multiple references of a procedure pointer [PR97245]
Date: Fri, 3 Nov 2023 19:56:20 +0100 [thread overview]
Message-ID: <trinity-9fc46089-aca1-43d9-a9f8-af8edf9ff588-1699037780911@3c-app-gmx-bs30> (raw)
[-- Attachment #1: Type: text/plain, Size: 402 bytes --]
Dear all,
this is a rather weird bug with a very simple fix. If a procedure pointer
is referenced in a CALL, a symbol was created shadowing the original
declaration if it was host-associated. Funnily, this affected only
references of the procedure pointer after the first CALL.
Regtested on x86_64-pc-linux-gnu. OK for mainline?
Would it be OK to backport this fix to 13-branch?
Thanks,
Harald
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr97245.diff --]
[-- Type: text/x-patch, Size: 2363 bytes --]
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
diff --git a/gcc/fortran/match.cc b/gcc/fortran/match.cc
index f848e52be4c..9e3571d3dbe 100644
--- a/gcc/fortran/match.cc
+++ b/gcc/fortran/match.cc
@@ -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)
{
diff --git a/gcc/testsuite/gfortran.dg/proc_ptr_53.f90 b/gcc/testsuite/gfortran.dg/proc_ptr_53.f90
new file mode 100644
index 00000000000..29dd08d9f75
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/proc_ptr_53.f90
@@ -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
next reply other threads:[~2023-11-03 18:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-03 18:56 Harald Anlauf [this message]
2023-11-03 21:02 ` Steve Kargl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=trinity-9fc46089-aca1-43d9-a9f8-af8edf9ff588-1699037780911@3c-app-gmx-bs30 \
--to=anlauf@gmx.de \
--cc=fortran@gcc.gnu.org \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).