]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR fortran/77632 ([F08] Pointer initialisation does not quite work with...
authorSteven G. Kargl <kargl@gcc.gnu.org>
Thu, 20 Jun 2019 23:50:54 +0000 (23:50 +0000)
committerSteven G. Kargl <kargl@gcc.gnu.org>
Thu, 20 Jun 2019 23:50:54 +0000 (23:50 +0000)
2019-06-20  Steven G. Kargl  <kargl@gcc.gnu.org>

Backport from mainline
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>

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

From-SVN: r272532

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

index a7e08d4dd535271b91814fcbb440f8e2fee83040..02b0d7a4568f1b0f87eb7a308db3677a6a8e307c 100644 (file)
@@ -1,3 +1,11 @@
+2019-06-20  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       Backport from mainline
+       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>
 
        Backport from mainline
index a005bd7962b4e0616bf49447b9b355b91292eba4..cf09420cfbe45de5c09c8f7e61be171f6e09d894 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 5536a17de0aa4e9f01f08811731de0c162d75fdf..8504dddb31e7337fb31cfe6ac7e47c0f38448db4 100644 (file)
@@ -1,3 +1,9 @@
+2019-06-20  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       Backport from mainline
+       PR fortran/77632
+       * gfortran.dg/pr77632_1.f90: New test.
+
 2019-06-20  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        Backport from mainline
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