PR fortran/95881 - ICE in resolve_symbol, at fortran/resolve.c:15175
authorHarald Anlauf <anlauf@gmx.de>
Sat, 27 Jun 2020 12:56:33 +0000 (14:56 +0200)
committerHarald Anlauf <anlauf@gmx.de>
Sat, 27 Jun 2020 12:57:28 +0000 (14:57 +0200)
Avoid NULL pointer dereference.

gcc/fortran/
PR fortran/95881
* resolve.c (resolve_symbol): Avoid NULL pointer dereference.

gcc/fortran/resolve.c
gcc/testsuite/gfortran.dg/pr95881.f90 [new file with mode: 0644]

index 6fa34caec5499ff514df9e93a8ffa22092b589d1..f3e8ffc204c044dd1496f83f371b7d7dc5a3ef1a 100644 (file)
@@ -15170,6 +15170,7 @@ resolve_symbol (gfc_symbol *sym)
   if (flag_coarray == GFC_FCOARRAY_LIB && sym->ts.type == BT_CLASS
       && sym->ts.u.derived && CLASS_DATA (sym)
       && CLASS_DATA (sym)->attr.codimension
+      && CLASS_DATA (sym)->ts.u.derived
       && (CLASS_DATA (sym)->ts.u.derived->attr.alloc_comp
          || CLASS_DATA (sym)->ts.u.derived->attr.pointer_comp))
     {
diff --git a/gcc/testsuite/gfortran.dg/pr95881.f90 b/gcc/testsuite/gfortran.dg/pr95881.f90
new file mode 100644 (file)
index 0000000..9f17176
--- /dev/null
@@ -0,0 +1,11 @@
+! { dg-do compile }
+! { dg-options "-fcoarray=lib" }
+! PR fortran/95881 - ICE in resolve_symbol, at fortran/resolve.c:15175
+
+program p
+  type t
+     real, allocatable :: a[:]
+  end type t
+  class(t) :: x     ! { dg-error "must be dummy, allocatable or pointer" }
+  allocate (x%a[*])
+end