From: Harald Anlauf <anlauf@gmx.de>
To: fortran@gcc.gnu.org
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH, committed] Fortran: NULL pointer dereference in gfc_simplify_image_index [PR104330]
Date: Mon, 17 Oct 2022 23:03:30 +0200 [thread overview]
Message-ID: <tikfv2$12kh$1@ciao.gmane.io> (raw)
In-Reply-To: <trinity-f4195e2f-23ac-47a9-acb2-f6a3abdf8d8c-1666040017524@3c-app-gmx-bs08>
[-- Attachment #1: Type: text/plain, Size: 375 bytes --]
Should have added the actual patch. Attached now.
Sorry for that.
Harald
Am 17.10.22 um 22:53 schrieb Harald Anlauf via Fortran:
> Dear all,
>
> I've pushed a very obvious fix for a NULL pointer dereference
> on behalf of Steve after regtesting on x86_64-pc-linux-gnu as
>
> https://gcc.gnu.org/g:84807af0ca6dfdb81abb8e925ce32acbcab29868
>
> Thanks,
> Harald
>
>
>
[-- Attachment #2: pr104330.diff --]
[-- Type: text/x-patch, Size: 1851 bytes --]
From 84807af0ca6dfdb81abb8e925ce32acbcab29868 Mon Sep 17 00:00:00 2001
From: Steve Kargl <kargl@gcc.gnu.org>
Date: Mon, 17 Oct 2022 22:42:40 +0200
Subject: [PATCH] Fortran: NULL pointer dereference in gfc_simplify_image_index
[PR104330]
gcc/fortran/ChangeLog:
PR fortran/104330
* simplify.cc (gfc_simplify_image_index): Do not dereference NULL
pointer.
gcc/testsuite/ChangeLog:
PR fortran/104330
* gfortran.dg/pr104330.f90: New test.
---
gcc/fortran/simplify.cc | 2 +-
gcc/testsuite/gfortran.dg/pr104330.f90 | 20 ++++++++++++++++++++
2 files changed, 21 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gfortran.dg/pr104330.f90
diff --git a/gcc/fortran/simplify.cc b/gcc/fortran/simplify.cc
index 6ac92cf9db8..9c2fea8c5f2 100644
--- a/gcc/fortran/simplify.cc
+++ b/gcc/fortran/simplify.cc
@@ -8266,7 +8266,7 @@ gfc_simplify_image_index (gfc_expr *coarray, gfc_expr *sub)
if (ref->type == REF_COMPONENT)
as = ref->u.ar.as;
- if (as->type == AS_DEFERRED)
+ if (!as || as->type == AS_DEFERRED)
return NULL;
/* "valid sequence of cosubscripts" are required; thus, return 0 unless
diff --git a/gcc/testsuite/gfortran.dg/pr104330.f90 b/gcc/testsuite/gfortran.dg/pr104330.f90
new file mode 100644
index 00000000000..9ff48e2f6cc
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr104330.f90
@@ -0,0 +1,20 @@
+! { dg-do compile }
+! { dg-options "-fcoarray=lib" }
+!
+! PR fortran/104330 - ICE in gfc_simplify_image_index
+! Contributed by G.Steinmetz
+
+program p
+ implicit none
+ type t
+ end type t
+ class(*), allocatable :: x[:]
+ class(t), allocatable :: y[:]
+ type(t), allocatable :: z[:]
+ allocate (real :: x[*])
+ print *, image_index(x, [1])
+ allocate (t :: y[*])
+ print *, image_index(y, [1])
+ allocate (t :: z[*])
+ print *, image_index(z, [1])
+end
--
2.35.3
prev parent reply other threads:[~2022-10-17 21:03 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-17 20:53 Harald Anlauf
2022-10-17 21:03 ` Harald Anlauf [this message]
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='tikfv2$12kh$1@ciao.gmane.io' \
--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).