From: Harald Anlauf <anlauf@gmx.de>
To: fortran <fortran@gcc.gnu.org>, gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [committed] PR fortran/100892 - ICE on procedure pointer to function returning array of size n
Date: Wed, 30 Mar 2022 22:43:24 +0200 [thread overview]
Message-ID: <trinity-43ae917d-ac95-4992-94c1-862ecd9b52d5-1648673004681@3c-app-gmx-bap30> (raw)
[-- Attachment #1: Type: text/plain, Size: 242 bytes --]
Dear all,
I committed the attached patch as obvious: we had a NULL pointer
dereference when checking the arguments of the ASSOCIATED intrinsic
when the target was an array-valued function.
Regtested on x86_64-pc-linux-gnu.
Thanks,
Harald
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr100892.diff --]
[-- Type: text/x-patch, Size: 1991 bytes --]
From b4e4b35f4ebe561826489bed971324efc99c5423 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Wed, 30 Mar 2022 22:36:12 +0200
Subject: [PATCH] Fortran: NULL pointer dereference checking arguments to
ASSOCIATED intrinsic
gcc/fortran/ChangeLog:
PR fortran/100892
* check.cc (gfc_check_associated): Avoid NULL pointer dereference.
gcc/testsuite/ChangeLog:
PR fortran/100892
* gfortran.dg/associated_target_8.f90: New test.
---
gcc/fortran/check.cc | 2 +-
.../gfortran.dg/associated_target_8.f90 | 16 ++++++++++++++++
2 files changed, 17 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gfortran.dg/associated_target_8.f90
diff --git a/gcc/fortran/check.cc b/gcc/fortran/check.cc
index fc97bb1371e..0c2cb50c6a7 100644
--- a/gcc/fortran/check.cc
+++ b/gcc/fortran/check.cc
@@ -1504,7 +1504,7 @@ gfc_check_associated (gfc_expr *pointer, gfc_expr *target)
argument of intrinsic inquiry functions. */
if (pointer->rank != -1 && !rank_check (target, 0, pointer->rank))
t = false;
- if (target->rank > 0)
+ if (target->rank > 0 && target->ref)
{
for (i = 0; i < target->rank; i++)
if (target->ref->u.ar.dimen_type[i] == DIMEN_VECTOR)
diff --git a/gcc/testsuite/gfortran.dg/associated_target_8.f90 b/gcc/testsuite/gfortran.dg/associated_target_8.f90
new file mode 100644
index 00000000000..75c2740a188
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/associated_target_8.f90
@@ -0,0 +1,16 @@
+! { dg-do compile }
+! PR fortran/100892 - procedure pointer to function returning array of size n
+
+module m
+ implicit none
+ procedure(func1), pointer :: my_ptr => null()
+contains
+ subroutine test_sub
+ if (associated (my_ptr, func1)) print *,'associated'
+ end subroutine test_sub
+ function func1 (n)
+ integer, intent(in) :: n
+ real, dimension(n) :: func1
+ func1 = 0.
+ end function
+end module m
--
2.34.1
reply other threads:[~2022-03-30 20:43 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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-43ae917d-ac95-4992-94c1-862ecd9b52d5-1648673004681@3c-app-gmx-bap30 \
--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).