public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-5970] Fortran: error recovery after invalid use of CLASS variable [PR103475]
@ 2023-02-13 21:06 Harald Anlauf
  0 siblings, 0 replies; only message in thread
From: Harald Anlauf @ 2023-02-13 21:06 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:2ce7e2a83e18a27fe9c659f8667fc24f0df4ea9a

commit r13-5970-g2ce7e2a83e18a27fe9c659f8667fc24f0df4ea9a
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Mon Feb 13 22:02:44 2023 +0100

    Fortran: error recovery after invalid use of CLASS variable [PR103475]
    
    gcc/fortran/ChangeLog:
    
            PR fortran/103475
            * primary.cc (gfc_expr_attr): Avoid NULL pointer dereference for
            invalid use of CLASS variable.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/103475
            * gfortran.dg/pr103475.f90: New test.

Diff:
---
 gcc/fortran/primary.cc                 |  2 +-
 gcc/testsuite/gfortran.dg/pr103475.f90 | 11 +++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/primary.cc b/gcc/fortran/primary.cc
index 28ce5fea865..1bea17d44fe 100644
--- a/gcc/fortran/primary.cc
+++ b/gcc/fortran/primary.cc
@@ -2770,7 +2770,7 @@ gfc_expr_attr (gfc_expr *e)
 	{
 	  gfc_symbol *sym = e->value.function.esym->result;
 	  attr = sym->attr;
-	  if (sym->ts.type == BT_CLASS)
+	  if (sym->ts.type == BT_CLASS && sym->attr.class_ok)
 	    {
 	      attr.dimension = CLASS_DATA (sym)->attr.dimension;
 	      attr.pointer = CLASS_DATA (sym)->attr.class_pointer;
diff --git a/gcc/testsuite/gfortran.dg/pr103475.f90 b/gcc/testsuite/gfortran.dg/pr103475.f90
new file mode 100644
index 00000000000..6cce5e8ebf7
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr103475.f90
@@ -0,0 +1,11 @@
+! { dg-do compile }
+! { dg-options "-O2 -Wall" }
+! PR fortran/103475 - ICE in gfc_expr_attr
+! Contributed by G.Steinmetz
+
+program p
+  type t
+  end type
+  class(t) :: x ! { dg-error "must be dummy, allocatable or pointer" }
+  y = x()       ! { dg-error "Cannot convert invalid class" }
+end

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

only message in thread, other threads:[~2023-02-13 21:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-13 21:06 [gcc r13-5970] Fortran: error recovery after invalid use of CLASS variable [PR103475] 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).