[committed,8/9/10/11,Regression] ICE with allocatable coarray, class and associate in resolve_assoc_var, at fortran/resolve.c:8750

Message ID trinity-0699ec3e-d201-416e-beef-86ff9967ae59-1593553399850@3c-app-gmx-bs42
State New
Headers show
Series
  • [committed,8/9/10/11,Regression] ICE with allocatable coarray, class and associate in resolve_assoc_var, at fortran/resolve.c:8750
Related show

Commit Message

Harald Anlauf June 30, 2020, 9:43 p.m.
Committed as obvious to master.

Will backport as seems fit.

Thanks,
Harald


PR fortran/88379 - ICE with allocatable coarray, class and associate

Catch NULL pointer dereference for ASSOCIATE on allocatable coarray variable.

gcc/fortran/
	PR fortran/88379
	* resolve.c (resolve_assoc_var): Avoid NULL pointer dereference.

Patch

diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index f3e8ffc204c..4a2abd00f4a 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -9045,7 +9045,7 @@  resolve_assoc_var (gfc_symbol* sym, bool resolve_target)
 	  as = NULL;
 	  sym->ts = *ts;
 	  sym->ts.type = BT_CLASS;
-	  attr = CLASS_DATA (sym)->attr;
+	  attr = CLASS_DATA (sym) ? CLASS_DATA (sym)->attr : sym->attr;
 	  attr.class_ok = 0;
 	  attr.associate_var = 1;
 	  attr.dimension = attr.codimension = 0;
diff --git a/gcc/testsuite/gfortran.dg/pr88379.f90 b/gcc/testsuite/gfortran.dg/pr88379.f90
new file mode 100644
index 00000000000..48a23af50c5
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr88379.f90
@@ -0,0 +1,11 @@ 
+! { dg-do compile }
+! { dg-options "-fcoarray=single" }
+! PR fortran/88379 - ICE with allocatable coarray, class and associate
+
+program p
+  type t
+  end type t
+  class(t), allocatable :: x[:]
+  associate (y => x)
+  end associate
+end