]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR fortran/95978 - ICE in gfc_match_data, at fortran/decl.c:731
authorHarald Anlauf <anlauf@gmx.de>
Mon, 29 Jun 2020 21:20:16 +0000 (23:20 +0200)
committerHarald Anlauf <anlauf@gmx.de>
Tue, 30 Jun 2020 18:46:44 +0000 (20:46 +0200)
Catch NULL pointer dereference on invalid DATA statement.

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

(cherry picked from commit 583812c2e2f3593823622b0a5821d957c832dbd0)

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

index adcd371b2d1f9e07660ab076af6426992c1670cc..ad3ad1c8b8923f20b2a2f7642ce0a3e8c688e6ad 100644 (file)
@@ -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 (file)
index 0000000..47bd706
--- /dev/null
@@ -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