[committed] PR fortran/95978 - [10/11 Regression] ICE in gfc_match_data, at fortran/decl.c:731

Message ID trinity-8115ac0f-9400-417b-8058-c3fd5c02e275-1593465868888@3c-app-gmx-bap46
State New
Headers show
Series
  • [committed] PR fortran/95978 - [10/11 Regression] ICE in gfc_match_data, at fortran/decl.c:731
Related show

Commit Message

Harald Anlauf June 29, 2020, 9:24 p.m.
Committed as obvious on mastger.

Regtested on x86_64-pc-linux-gnu.

Will backport to 10-branch.

Thanks,
Harald


PR fortran/95978 - ICE in gfc_match_data, at fortran/decl.c:731

Catch NULL pointer dereference on invalid DATA statement.

gcc/fortran/
	PR fortran/95978
	* decl.c (gfc_match_data): Avoid NULL pointer dereference.

Patch

diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index ac1f63f66e0..f38def4c291 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -728,7 +728,7 @@  gfc_match_data (void)
 	  gfc_constructor *c;
 	  c = gfc_constructor_first (new_data->value->expr->value.constructor);
 	  for (; c; c = gfc_constructor_next (c))
-	    if (c->expr->ts.type == BT_BOZ)
+	    if (c->expr && c->expr->ts.type == BT_BOZ)
 	      {
 		gfc_error ("BOZ literal constant at %L cannot appear in a "
 			   "structure constructor", &c->expr->where);
diff --git a/gcc/testsuite/gfortran.dg/pr95978.f90 b/gcc/testsuite/gfortran.dg/pr95978.f90
new file mode 100644
index 00000000000..47bd7067096
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr95978.f90
@@ -0,0 +1,10 @@ 
+! { dg-do compile }
+! PR fortran/95978 - ICE in gfc_match_data, at fortran/decl.c:731
+
+program p
+  type t
+     integer :: a
+     type(t), allocatable :: b
+     data c /t(1)/               ! { dg-error "Unexpected DATA statement" }
+  end type t
+end