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>
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
--- /dev/null
+! { 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