diff mbox series

[committed] PR fortran/95340 - [10/11 Regression] ICE in gfc_match_select_rank, at fortran/match.c:6690

Message ID trinity-177e206d-7a37-42c3-a3af-2762d1f3e001-1593354594536@3c-app-gmx-bap66
State New
Headers show
Series [committed] PR fortran/95340 - [10/11 Regression] ICE in gfc_match_select_rank, at fortran/match.c:6690 | expand

Commit Message

Harald Anlauf June 28, 2020, 2:29 p.m. UTC
Committed as obvious.

NULL pointer dereference originally found by Steve.  My patch is shorter. :-)

Regtested on x86_64-pc-linux-gnu.

Thanks,
Harald


PR fortran/95340 - ICE in gfc_match_select_rank, at fortran/match.c:6690

Do not dereference NULL pointer when querying array shape of possibly
improperly delared variable.

gcc/fortran/
	PR fortran/95340
	* match.c (gfc_match_select_rank): Do not dereference NULL pointer.
diff mbox series

Patch

diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c
index b011634792e..db5174f3f21 100644
--- a/gcc/fortran/match.c
+++ b/gcc/fortran/match.c
@@ -6695,7 +6695,8 @@  gfc_match_select_rank (void)
       if (expr1->symtree)
 	{
 	  sym = expr1->symtree->n.sym;
-	  as = sym->ts.type == BT_CLASS ? CLASS_DATA (sym)->as : sym->as;
+	  as = (sym->ts.type == BT_CLASS
+		&& CLASS_DATA (sym)) ? CLASS_DATA (sym)->as : sym->as;
 	}

       if (expr1->expr_type != EXPR_VARIABLE
diff --git a/gcc/testsuite/gfortran.dg/pr95340.f90 b/gcc/testsuite/gfortran.dg/pr95340.f90
new file mode 100644
index 00000000000..edcdc935057
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr95340.f90
@@ -0,0 +1,10 @@ 
+! { dg-do compile }
+! PR fortran/95340 - ICE in gfc_match_select_rank, at fortran/match.c:6690
+
+program p
+  type t
+  end type t
+  class(t) :: z   ! { dg-error "must be dummy, allocatable or pointer" }
+  select rank (z) ! { dg-error "must be an assumed rank variable" }
+  end select      ! { dg-error "Expecting END PROGRAM" }
+end