PR fortran/95881 - [9/10/11 Regression] ICE in resolve_symbol, at fortran/resolve.c:15175

Message ID trinity-50debc52-463c-466c-9c70-f69ea7e33351-1593200224459@3c-app-gmx-bap71
State New
Headers show
Series
  • PR fortran/95881 - [9/10/11 Regression] ICE in resolve_symbol, at fortran/resolve.c:15175
Related show

Commit Message

Harald Anlauf June 26, 2020, 7:37 p.m.
Dear all,

here's another NULL pointer dereference on invalid code.

Regtested on x86_64-pc-linux-gnu.

OK for master / backports where appropriate?

Thanks,
Harald


PR fortran/95881 - ICE in resolve_symbol, at fortran/resolve.c:15175

Avoid NULL pointer dereference.

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

Comments

Peter Bergner via Gcc-patches June 27, 2020, 8:57 a.m. | #1
Hi Harald,


> here's another NULL pointer dereference on invalid code.

> 

> Regtested on x86_64-pc-linux-gnu.

> 

> OK for master / backports where appropriate?


OK.

(Also would have classified as obvious and simple, I think).

Thanks for the patch

Regards

	Thomas

Patch

diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 6fa34caec54..55f57e2769b 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -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
index 00000000000..13146967e9f
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr95881.f90
@@ -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