aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarald Anlauf <anlauf@gmx.de>2022-12-03 19:21:07 +0100
committerHarald Anlauf <anlauf@gmx.de>2022-12-04 20:27:34 +0100
commit9123863828b2f86e7a6aafba38738e7204ed19ca (patch)
tree218cb8a37b5ea90aa57a991e441567673586972a
parent079add3ad39d6620d34665dd9c26c21951eb657c (diff)
downloadgcc-9123863828b2f86e7a6aafba38738e7204ed19ca.zip
gcc-9123863828b2f86e7a6aafba38738e7204ed19ca.tar.gz
gcc-9123863828b2f86e7a6aafba38738e7204ed19ca.tar.bz2
Fortran: error recovery handling invalid CLASS variable [PR107899]
gcc/fortran/ChangeLog: PR fortran/107899 * resolve.cc (resolve_deallocate_expr): Avoid NULL pointer dereference on invalid CLASS variable. gcc/testsuite/ChangeLog: PR fortran/107899 * gfortran.dg/pr107899.f90: New test.
-rw-r--r--gcc/fortran/resolve.cc2
-rw-r--r--gcc/testsuite/gfortran.dg/pr107899.f9013
2 files changed, 14 insertions, 1 deletions
diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 3396c6c..75dc4b5 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 0000000..e47b57b
--- /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