public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Harald Anlauf <anlauf@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r10-10881] Fortran: improve error recovery for EXTENDS_TYPE_OF() [PR106121]
Date: Sun,  3 Jul 2022 20:29:43 +0000 (GMT)	[thread overview]
Message-ID: <20220703202943.14E54385840C@sourceware.org> (raw)

https://gcc.gnu.org/g:8bb7567f5a3e67ab91614d4538eb3a14a5a76274

commit r10-10881-g8bb7567f5a3e67ab91614d4538eb3a14a5a76274
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Tue Jun 28 22:29:28 2022 +0200

    Fortran: improve error recovery for EXTENDS_TYPE_OF() [PR106121]
    
    gcc/fortran/ChangeLog:
    
            PR fortran/106121
            * simplify.c (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>
    (cherry picked from commit b8f284d3673004dffae714b56ed663467c2a52a7)

Diff:
---
 gcc/fortran/simplify.c                          |  4 ++++
 gcc/testsuite/gfortran.dg/extends_type_of_4.f90 | 20 ++++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c
index a4e014a746f..29d4c695302 100644
--- a/gcc/fortran/simplify.c
+++ b/gcc/fortran/simplify.c
@@ -3060,6 +3060,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


                 reply	other threads:[~2022-07-03 20:29 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=20220703202943.14E54385840C@sourceware.org \
    --to=anlauf@gcc.gnu.org \
    --cc=gcc-cvs@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).