* [PATCH] Fortran: improve error recovery for EXTENDS_TYPE_OF() [PR106121]
@ 2022-06-28 20:36 Harald Anlauf
2022-06-29 15:00 ` Tobias Burnus
0 siblings, 1 reply; 2+ messages in thread
From: Harald Anlauf @ 2022-06-28 20:36 UTC (permalink / raw)
To: fortran, gcc-patches
[-- 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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Fortran: improve error recovery for EXTENDS_TYPE_OF() [PR106121]
2022-06-28 20:36 [PATCH] Fortran: improve error recovery for EXTENDS_TYPE_OF() [PR106121] Harald Anlauf
@ 2022-06-29 15:00 ` Tobias Burnus
0 siblings, 0 replies; 2+ messages in thread
From: Tobias Burnus @ 2022-06-29 15:00 UTC (permalink / raw)
To: Harald Anlauf, fortran, gcc-patches
On 28.06.22 22:36, Harald Anlauf via Gcc-patches wrote:
> 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.
LGTM – and I do note that Steven also okayed it in the PR.
Thanks,
Tobias
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-06-29 15:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-28 20:36 [PATCH] Fortran: improve error recovery for EXTENDS_TYPE_OF() [PR106121] Harald Anlauf
2022-06-29 15:00 ` Tobias Burnus
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).