]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/18518 (equivalenced variables are not saved)
authorJakub Jelinek <jakub@redhat.com>
Tue, 27 Sep 2005 21:46:14 +0000 (23:46 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 27 Sep 2005 21:46:14 +0000 (23:46 +0200)
PR fortran/18518
* trans-common.c (build_equiv_decl): Add IS_SAVED argument.
If it is true, set TREE_STATIC on the decl.
(create_common): If any symbol in equivalence has SAVE attribute,
pass true as last argument to build_equiv_decl.

* gfortran.fortran-torture/execute/save_2.f90: New decl.

From-SVN: r104712

gcc/fortran/ChangeLog
gcc/fortran/trans-common.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.fortran-torture/execute/save_2.f90 [new file with mode: 0644]

index 2644f58f2c0fd9cfd5041f4a02a2677b33d2fa88..4334c3c6ae2b78c137a18710a1bd4d773d414e36 100644 (file)
@@ -1,3 +1,11 @@
+2005-09-27  Jakub Jelinek  <jakub@redhat.com>
+
+       PR fortran/18518
+       * trans-common.c (build_equiv_decl): Add IS_SAVED argument.
+       If it is true, set TREE_STATIC on the decl.
+       (create_common): If any symbol in equivalence has SAVE attribute,
+       pass true as last argument to build_equiv_decl.
+
 2005-09-24  Janne Blomqvist  <jblomqvi@cc.hut.fi>
 
        * trans-io.c (gfc_build_io_library_fndecls): Add entry
index 039d86da662ca18ba9a1b0b7dc6b5471ea22aa32..de47f90630590132f7b9d2d5fcfd77738afabc91 100644 (file)
@@ -268,7 +268,7 @@ build_field (segment_info *h, tree union_type, record_layout_info rli)
 /* Get storage for local equivalence.  */
 
 static tree
-build_equiv_decl (tree union_type, bool is_init)
+build_equiv_decl (tree union_type, bool is_init, bool is_saved)
 {
   tree decl;
   char name[15];
@@ -286,7 +286,8 @@ build_equiv_decl (tree union_type, bool is_init)
   DECL_ARTIFICIAL (decl) = 1;
   DECL_IGNORED_P (decl) = 1;
 
-  if (!gfc_can_put_var_on_stack (DECL_SIZE_UNIT (decl)))
+  if (!gfc_can_put_var_on_stack (DECL_SIZE_UNIT (decl))
+      || is_saved)
     TREE_STATIC (decl) = 1;
 
   TREE_ADDRESSABLE (decl) = 1;
@@ -385,6 +386,7 @@ create_common (gfc_common_head *com, segment_info * head, bool saw_equiv)
   record_layout_info rli;
   tree decl;
   bool is_init = false;
+  bool is_saved = false;
 
   /* Declare the variables inside the common block.
      If the current common block contains any equivalence object, then
@@ -410,13 +412,17 @@ create_common (gfc_common_head *com, segment_info * head, bool saw_equiv)
       /* Has initial value.  */
       if (s->sym->value)
         is_init = true;
+
+      /* Has SAVE attribute.  */
+      if (s->sym->attr.save)
+        is_saved = true;
     }
   finish_record_layout (rli, true);
 
   if (com)
     decl = build_common_decl (com, union_type, is_init);
   else
-    decl = build_equiv_decl (union_type, is_init);
+    decl = build_equiv_decl (union_type, is_init, is_saved);
 
   if (is_init)
     {
index 61bf586dbf81466df38aa131b2d0dfaf0694fd27..e6375b5576bdd6c02a3b20743a6286deca13a321 100644 (file)
@@ -1,3 +1,8 @@
+2005-09-27  Jakub Jelinek  <jakub@redhat.com>
+
+       PR fortran/18518
+       * gfortran.fortran-torture/execute/save_2.f90: New decl.
+
 2005-09-27  Devang Patel  <dpatel@apple.com>
 
        PR tree-optimization/23625
diff --git a/gcc/testsuite/gfortran.fortran-torture/execute/save_2.f90 b/gcc/testsuite/gfortran.fortran-torture/execute/save_2.f90
new file mode 100644 (file)
index 0000000..c3775bb
--- /dev/null
@@ -0,0 +1,23 @@
+! PR fortran/18518
+      program main
+       call foo
+       call bar
+       call foo
+      end program main
+
+      subroutine foo
+       integer i,g,h
+       data i/0/
+       equivalence (g,h)
+       save g
+       if (i == 0) then
+          i = 1
+          h = 12345
+       end if
+       if (h .ne. 12345) call abort
+      end subroutine foo
+
+      subroutine bar
+       integer a(10)
+       a = 34
+      end subroutine bar