diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc index 3396c6ce4a7..75dc4b59105 100644 --- a/gcc/fortran/resolve.cc +++ b/gcc/fortran/resolve.cc @@ -7570,7 +7570,7 @@ resolve_deallocate_expr (gfc_expr *e) sym = e->symtree->n.sym; unlimited = UNLIMITED_POLY(sym); - if (sym->ts.type == BT_CLASS) + if (sym->ts.type == BT_CLASS && sym->attr.class_ok && CLASS_DATA (sym)) { allocatable = CLASS_DATA (sym)->attr.allocatable; pointer = CLASS_DATA (sym)->attr.class_pointer; diff --git a/gcc/testsuite/gfortran.dg/pr107899.f90 b/gcc/testsuite/gfortran.dg/pr107899.f90 new file mode 100644 index 00000000000..e47b57b7b91 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr107899.f90 @@ -0,0 +1,13 @@ +! { dg-do compile } +! { dg-options "-fcoarray=single" } +! PR fortran/107899 - ICE in resolve_deallocate_expr +! Contributed by G.Steinmetz + +program p + type t + end type + class(t), target :: x[:] ! { dg-error "deferred shape" } + if (allocated (x)) then ! { dg-error "must be ALLOCATABLE" } + deallocate (x) ! { dg-error "must be ALLOCATABLE or a POINTER" } + end if +end