Skip to content

Commit 117848f

Browse files
committed
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.
1 parent f8cb07a commit 117848f

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

gcc/fortran/expr.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4996,14 +4996,14 @@ get_union_initializer (gfc_symbol *union_type, gfc_component **map_p)
49964996
static bool
49974997
class_allocatable (gfc_component *comp)
49984998
{
4999-
return comp->ts.type == BT_CLASS && CLASS_DATA (comp)
4999+
return comp->ts.type == BT_CLASS && comp->attr.class_ok && CLASS_DATA (comp)
50005000
&& CLASS_DATA (comp)->attr.allocatable;
50015001
}
50025002

50035003
static bool
50045004
class_pointer (gfc_component *comp)
50055005
{
5006-
return comp->ts.type == BT_CLASS && CLASS_DATA (comp)
5006+
return comp->ts.type == BT_CLASS && comp->attr.class_ok && CLASS_DATA (comp)
50075007
&& CLASS_DATA (comp)->attr.pointer;
50085008
}
50095009

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
! { dg-do compile }
2+
! PR fortran/108434 - ICE in class_allocatable
3+
! Contributed by G.Steinmetz
4+
5+
program p
6+
type t
7+
class(c), pointer :: a(2) ! { dg-error "must have a deferred shape" }
8+
end type t
9+
class(t), allocatable :: x
10+
class(t), pointer :: y
11+
end

0 commit comments

Comments
 (0)