From: Harald Anlauf <anlauf@gmx.de>
To: fortran <fortran@gcc.gnu.org>, gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH] Fortran: improve error recovery for EXTENDS_TYPE_OF() [PR106121]
Date: Tue, 28 Jun 2022 22:36:22 +0200 [thread overview]
Message-ID: <trinity-cbed321f-80c8-4a64-8e1a-343a6abea159-1656448582471@3c-app-gmx-bs57> (raw)
[-- Attachment #1: Type: text/plain, Size: 416 bytes --]
Dear all,
the simplification of EXTENDS_TYPE_OF() did not handle the
situation that one of its arguments were a CLASS variable
that was improperly declared. NULL pointer dereference.
The fix is obvious. Steve found a similar solution, which
is why I added him as co-author.
Regtested on x86_64-pc-linux-gnu.
Will commit to mainline as obvious within 24 hours unless
there are loud objections.
Thanks,
Harald
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fortran-improve-error-recovery-for-EXTENDS_TYPE_OF-P.patch --]
[-- Type: text/x-patch, Size: 2283 bytes --]
From 55aacfd22d73edfb38871e211f85b2ae69fd0072 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Tue, 28 Jun 2022 22:29:28 +0200
Subject: [PATCH] Fortran: improve error recovery for EXTENDS_TYPE_OF()
[PR106121]
gcc/fortran/ChangeLog:
PR fortran/106121
* simplify.cc (gfc_simplify_extends_type_of): Do not attempt to
simplify when one of the arguments is a CLASS variable that was
not properly declared.
gcc/testsuite/ChangeLog:
PR fortran/106121
* gfortran.dg/extends_type_of_4.f90: New test.
Co-authored-by: Steven G. Kargl <kargl@gcc.gnu.org>
---
gcc/fortran/simplify.cc | 4 ++++
.../gfortran.dg/extends_type_of_4.f90 | 20 +++++++++++++++++++
2 files changed, 24 insertions(+)
create mode 100644 gcc/testsuite/gfortran.dg/extends_type_of_4.f90
diff --git a/gcc/fortran/simplify.cc b/gcc/fortran/simplify.cc
index e8e3ec63669..ab59fbca622 100644
--- a/gcc/fortran/simplify.cc
+++ b/gcc/fortran/simplify.cc
@@ -3096,6 +3096,10 @@ gfc_simplify_extends_type_of (gfc_expr *a, gfc_expr *mold)
if (UNLIMITED_POLY (a) || UNLIMITED_POLY (mold))
return NULL;
+ if ((a->ts.type == BT_CLASS && !gfc_expr_attr (a).class_ok)
+ || (mold->ts.type == BT_CLASS && !gfc_expr_attr (mold).class_ok))
+ return NULL;
+
/* Return .false. if the dynamic type can never be an extension. */
if ((a->ts.type == BT_CLASS && mold->ts.type == BT_CLASS
&& !gfc_type_is_extension_of
diff --git a/gcc/testsuite/gfortran.dg/extends_type_of_4.f90 b/gcc/testsuite/gfortran.dg/extends_type_of_4.f90
new file mode 100644
index 00000000000..64373322387
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/extends_type_of_4.f90
@@ -0,0 +1,20 @@
+! { dg-do compile }
+! PR fortran/106121 - ICE in gfc_simplify_extends_type_of
+! Contributed by G.Steinmetz
+
+program p
+ type t
+ end type
+ type(t) :: x
+ class(t) :: y ! { dg-error "dummy, allocatable or pointer" }
+ print *, extends_type_of (x, y)
+end
+
+subroutine s
+ type t
+ integer :: i
+ end type
+ type(t) :: x
+ class(t) :: y ! { dg-error "dummy, allocatable or pointer" }
+ stop extends_type_of (x, y) ! { dg-error "STOP code" }
+end
--
2.35.3
next reply other threads:[~2022-06-28 20:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-28 20:36 Harald Anlauf [this message]
2022-06-29 15:00 ` Tobias Burnus
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-cbed321f-80c8-4a64-8e1a-343a6abea159-1656448582471@3c-app-gmx-bs57 \
--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).