]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/85798 (ICE in get_array_index, at fortran/data.c:69)
authorSteven G. Kargl <kargl@gcc.gnu.org>
Sat, 22 Dec 2018 23:23:02 +0000 (23:23 +0000)
committerSteven G. Kargl <kargl@gcc.gnu.org>
Sat, 22 Dec 2018 23:23:02 +0000 (23:23 +0000)
2018-12-22  Steven G . Kargl  <kargl@gcc.gnu.org>

PR fortran/85798
* decl.c (gfc_match_data): If a component of a derived type entity
appears in data statement, check that does not have the allocatable
attribute.

2018-12-22  Steven G . Kargl  <kargl@gcc.gnu.org>

PR fortran/85798
* gfortran.dg/pr85798.f90: New test.

From-SVN: r267362

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

index 3d391b0680ea67d1b62d80ed06aa6b335fa7d4dd..b52c215067f162d02d0476253e64116b38acdba8 100644 (file)
@@ -1,3 +1,10 @@
+2018-12-22  Steven G . Kargl  <kargl@gcc.gnu.org>
+
+       PR fortran/85798
+       * decl.c (gfc_match_data): If a component of a derived type entity
+       appears in data statement, check that does not have the allocatable
+       attribute.
 2018-12-22  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        Backport from trunk
index f7b597bc3fd80cace6eb35a82ea45f68bc131015..42879f063e2c190b9889f7eeeabf45a770e99f87 100644 (file)
@@ -552,6 +552,7 @@ match
 gfc_match_data (void)
 {
   gfc_data *new_data;
+  gfc_expr *e;
   match m;
 
   /* Before parsing the rest of a DATA statement, check F2008:c1206.  */
@@ -588,6 +589,30 @@ gfc_match_data (void)
          goto cleanup;
        }
 
+      /* Check for an entity with an allocatable component, which is not
+        allowed.  */
+      e = new_data->var->expr;
+      if (e)
+       {
+         bool invalid;
+
+         invalid = false;
+         for (gfc_ref *ref = e->ref; ref; ref = ref->next)
+           if ((ref->type == REF_COMPONENT
+                && ref->u.c.component->attr.allocatable)
+               || (ref->type == REF_ARRAY
+                   && e->symtree->n.sym->attr.pointer != 1
+                   && ref->u.ar.as && ref->u.ar.as->type == AS_DEFERRED))
+             invalid = true;
+
+         if (invalid)
+           {
+             gfc_error ("Allocatable component or deferred-shaped array "
+                        "near %C in DATA statement");
+             goto cleanup;
+           }
+       }
+
       m = top_val_list (new_data);
       if (m != MATCH_YES)
        goto cleanup;
index fd74e371c437f891cb3d272a8788a06208ad8ffe..9e983691fdcc4a4a22f61299b5dcde41a8e3b5c1 100644 (file)
@@ -1,3 +1,8 @@
+2018-12-22  Steven G . Kargl  <kargl@gcc.gnu.org>
+
+       PR fortran/85798
+       * gfortran.dg/pr85798.f90: New test.
+
 2018-12-22  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        Backport from trunk
diff --git a/gcc/testsuite/gfortran.dg/pr85798.f90 b/gcc/testsuite/gfortran.dg/pr85798.f90
new file mode 100644 (file)
index 0000000..1cc224d
--- /dev/null
@@ -0,0 +1,14 @@
+! { dg-do compile }
+program p
+   type t
+      integer, allocatable :: a(:)
+   end type
+   type u
+      real x
+      type(t) y
+   end type
+   type(t) :: z
+   type(u) :: q
+   data z%a(1) / 789 /     ! { dg-error "Allocatable component" }
+   data q%y%a(1) / 789 /   ! { dg-error "Allocatable component" }
+end