]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: improve error recovery for EXTENDS_TYPE_OF() [PR106121]
authorHarald Anlauf <anlauf@gmx.de>
Tue, 28 Jun 2022 20:29:28 +0000 (22:29 +0200)
committerHarald Anlauf <anlauf@gmx.de>
Sun, 3 Jul 2022 19:38:05 +0000 (21:38 +0200)
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>
(cherry picked from commit b8f284d3673004dffae714b56ed663467c2a52a7)

gcc/fortran/simplify.cc
gcc/testsuite/gfortran.dg/extends_type_of_4.f90 [new file with mode: 0644]

index 4a1a82b027346b37b3dc60a79788527aec28d384..2f4f13b6a830a00417c1b5529bf8b6c94b5cedf6 100644 (file)
@@ -3093,6 +3093,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 (file)
index 0000000..6437332
--- /dev/null
@@ -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