decl.c (match_data_constant): Fortran 2018 allows pointer initialization in a data...
authorSteven G. Kargl <kargl@gcc.gnu.org>
Sun, 27 May 2018 17:31:26 +0000 (17:31 +0000)
committerSteven G. Kargl <kargl@gcc.gnu.org>
Sun, 27 May 2018 17:31:26 +0000 (17:31 +0000)
2018-05-27  Steven G. Kargl  <kargl@gcc.gnu.org>

 * decl.c (match_data_constant):  Fortran 2018 allows pointer
 initialization in a data statement.

2018-05-27  Steven G. Kargl  <kargl@gcc.gnu.org>

 * gfortran.dg/data_stmt_pointer.f90: new test.

From-SVN: r260808

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

index 63d42976676aae2f163442ecb7b341eceebe9a05..95914aea938348c364d5688a28e527232d90c90c 100644 (file)
@@ -1,3 +1,8 @@
+2018-05-27  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       * decl.c (match_data_constant):  Fortran 2018 allows pointer
+       initialization in a data statement.
+
 2018-05-25  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/85839
index bd343b2b163429e20d76dfc4c3227eb5fd62e317..2fca8ad1f5dd0ccbb01f1d6375ad82909b88f6e3 100644 (file)
@@ -387,7 +387,20 @@ match_data_constant (gfc_expr **result)
       return m;
     }
   else if (m == MATCH_YES)
-    gfc_free_expr (*result);
+    {
+      /* F2018:R845 data-stmt-constant is initial-data-target.
+        A data-stmt-constant shall be ... initial-data-target if and
+        only if the corresponding data-stmt-object has the POINTER
+        attribute. ...  If data-stmt-constant is initial-data-target
+        the corresponding data statement object shall be
+        data-pointer-initialization compatible (7.5.4.6) with the initial
+        data target; the data statement object is initially associated
+        with the target.  */
+      if ((*result)->symtree->n.sym->attr.save
+         && (*result)->symtree->n.sym->attr.target)
+       return m;
+      gfc_free_expr (*result);
+    }
 
   gfc_current_locus = old_loc;
 
index a897b47cb1320eb03fe1455c5f623968508f65d5..0ec5cee07aea83d835453b9865a40e8976cb6383 100644 (file)
@@ -1,3 +1,7 @@
+2018-05-27  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       * gfortran.dg/data_stmt_pointer.f90: new test.
+
 2018-05-27  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/85918
diff --git a/gcc/testsuite/gfortran.dg/data_stmt_pointer.f90 b/gcc/testsuite/gfortran.dg/data_stmt_pointer.f90
new file mode 100644 (file)
index 0000000..923860e
--- /dev/null
@@ -0,0 +1,19 @@
+! { dg-do run }
+program foo
+   real, pointer :: p
+   real, save, target :: x = 42
+   data p / x /
+   if (p /= 42) stop 1
+   call bar
+end program foo
+
+subroutine bar
+   type bah
+     integer, pointer :: p
+   end type bah
+   type(bah) a
+   integer, save, target :: i = 42
+   data a%p / i /
+   if (a%p /= 42) stop 2
+end subroutine
+