re PR fortran/77632 ([F08] Pointer initialisation does not quite work with arrays)
authorSteven G. Kargl <kargl@gcc.gnu.org>
Thu, 20 Jun 2019 22:16:29 +0000 (22:16 +0000)
committerSteven G. Kargl <kargl@gcc.gnu.org>
Thu, 20 Jun 2019 22:16:29 +0000 (22:16 +0000)
2019-06-20  Steven G. Kargl  <kargl@gcc.gnu.org>

PR fortran/77632
* /decl.c (variable_decl): Mark a variable that is a target in pointer
initialization when in PROGRAM, MODULE, or SUBMODULE scope with an
implicit save.

2019-06-20  Steven G. Kargl  <kargl@gcc.gnu.org>

PR fortran/77632
* gfortran.dg/pr77632_1.f90: New test.

From-SVN: r272526

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

index 7b71ee43e0b4ac6fae1afe39231c0bb2cd136235..56aca1f9b1e2971e2a141367173a904fd7ec9a36 100644 (file)
@@ -1,3 +1,10 @@
+2019-06-20  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       PR fortran/77632
+       * /decl.c (variable_decl): Mark a variable that is a target in pointer
+       initialization when in PROGRAM, MODULE, or SUBMODULE scope with an
+       implicit save.
+
 2019-06-20  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        PR fortran/86587
index 7fcb60ab7ab85092a4d90c7fe13582a10ec85be3..f5517f0d75f0d38f06164628cf5e0c2cebbe3c72 100644 (file)
@@ -2779,6 +2779,16 @@ variable_decl (int elem)
          m = match_pointer_init (&initializer, 0);
          if (m != MATCH_YES)
            goto cleanup;
+
+         /* The target of a pointer initialization must have the SAVE
+            attribute.  A variable in PROGRAM, MODULE, or SUBMODULE scope
+            is implicit SAVEd.  Explicitly, set the SAVE_IMPLICIT value.  */
+         if (initializer->expr_type == EXPR_VARIABLE
+             && initializer->symtree->n.sym->attr.save == SAVE_NONE
+             && (gfc_current_state () == COMP_PROGRAM
+                 || gfc_current_state () == COMP_MODULE
+                 || gfc_current_state () == COMP_SUBMODULE))
+           initializer->symtree->n.sym->attr.save = SAVE_IMPLICIT;
        }
       else if (gfc_match_char ('=') == MATCH_YES)
        {
index 48ca72f0e533b5fc8774d37a0affb0d503269958..440284de43fe2d0db84b4ebaaeb5a7661b49137b 100644 (file)
@@ -1,3 +1,8 @@
+2019-06-20  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       PR fortran/77632
+       * gfortran.dg/pr77632_1.f90: New test.
+
 2019-06-20  Marek Polacek  <polacek@redhat.com>
 
        PR c++/68265
diff --git a/gcc/testsuite/gfortran.dg/pr77632_1.f90 b/gcc/testsuite/gfortran.dg/pr77632_1.f90
new file mode 100644 (file)
index 0000000..13fed59
--- /dev/null
@@ -0,0 +1,7 @@
+! { dg-do run }
+program foo
+   implicit none
+   real, target :: a
+   real, pointer :: b => a
+   if (associated(b, a) .eqv. .false.) stop 1
+end program foo