public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-5260] Fortran: error recovery for invalid CLASS component [PR108434]
@ 2023-01-19 18:23 Harald Anlauf
  0 siblings, 0 replies; only message in thread
From: Harald Anlauf @ 2023-01-19 18:23 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:117848f425a3c0eda85517b4bdaf2ebe3bc705c2

commit r13-5260-g117848f425a3c0eda85517b4bdaf2ebe3bc705c2
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Wed Jan 18 22:13:29 2023 +0100

    Fortran: error recovery for invalid CLASS component [PR108434]
    
    gcc/fortran/ChangeLog:
    
            PR fortran/108434
            * expr.cc (class_allocatable): Prevent NULL pointer dereference
            or invalid read.
            (class_pointer): Likewise.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/108434
            * gfortran.dg/pr108434.f90: New test.

Diff:
---
 gcc/fortran/expr.cc                    |  4 ++--
 gcc/testsuite/gfortran.dg/pr108434.f90 | 11 +++++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc
index 5ec369c9cd8..3036b1be60f 100644
--- a/gcc/fortran/expr.cc
+++ b/gcc/fortran/expr.cc
@@ -4996,14 +4996,14 @@ get_union_initializer (gfc_symbol *union_type, gfc_component **map_p)
 static bool
 class_allocatable (gfc_component *comp)
 {
-  return comp->ts.type == BT_CLASS && CLASS_DATA (comp)
+  return comp->ts.type == BT_CLASS && comp->attr.class_ok && CLASS_DATA (comp)
     && CLASS_DATA (comp)->attr.allocatable;
 }
 
 static bool
 class_pointer (gfc_component *comp)
 {
-  return comp->ts.type == BT_CLASS && CLASS_DATA (comp)
+  return comp->ts.type == BT_CLASS && comp->attr.class_ok && CLASS_DATA (comp)
     && CLASS_DATA (comp)->attr.pointer;
 }
 
diff --git a/gcc/testsuite/gfortran.dg/pr108434.f90 b/gcc/testsuite/gfortran.dg/pr108434.f90
new file mode 100644
index 00000000000..e1768a57574
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr108434.f90
@@ -0,0 +1,11 @@
+! { dg-do compile }
+! PR fortran/108434 - ICE in class_allocatable
+! Contributed by G.Steinmetz
+
+program p
+  type t
+     class(c), pointer :: a(2) ! { dg-error "must have a deferred shape" }
+  end type t
+  class(t), allocatable :: x
+  class(t), pointer     :: y
+end

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

only message in thread, other threads:[~2023-01-19 18:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-19 18:23 [gcc r13-5260] Fortran: error recovery for invalid CLASS component [PR108434] 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).