public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-4484] Fortran: error recovery handling invalid CLASS variable [PR107899]
@ 2022-12-04 19:34 Harald Anlauf
  0 siblings, 0 replies; only message in thread
From: Harald Anlauf @ 2022-12-04 19:34 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:9123863828b2f86e7a6aafba38738e7204ed19ca

commit r13-4484-g9123863828b2f86e7a6aafba38738e7204ed19ca
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Sat Dec 3 19:21:07 2022 +0100

    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.

Diff:
---
 gcc/fortran/resolve.cc                 |  2 +-
 gcc/testsuite/gfortran.dg/pr107899.f90 | 13 +++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-12-04 19:34 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-04 19:34 [gcc r13-4484] Fortran: error recovery handling invalid CLASS variable [PR107899] Harald Anlauf

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).