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.
(cherry picked from commit
117848f425a3c0eda85517b4bdaf2ebe3bc705c2)
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;
}
--- /dev/null
+! { 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