re PR fortran/32103 (Module with equivalence draws "unsatisfied reference")
authorPaul Thomas <pault@gcc.gnu.org>
Thu, 31 May 2007 07:45:50 +0000 (07:45 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Thu, 31 May 2007 07:45:50 +0000 (07:45 +0000)
2007-05-31  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/32103
* module.c (mio_symtree_ref): If an equivalence group member
is not used, give it a hidden symbol and set the pointer_info.
(load_equiv): Only free the equivalence if none of the members
are used.

2007-05-31  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/32103
* gfortran.dg/module_equivalence_3.f90: New test.

From-SVN: r125216

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

index e61c6e46bf1ed2ff82a656859e4d8fcb144bf2f8..a4ebacabfafa501a414ff0aefc93b728e979b1ea 100644 (file)
@@ -1,4 +1,4 @@
-2007-05-29  Daniel Franke  <franke.daniel@gmail.com>
+2007-05-31  Paul Thomas  <pault@gcc.gnu.org>\r\r PR fortran/32103\r       * module.c (mio_symtree_ref): If an equivalence group member\r   is not used, give it a hidden symbol and set the pointer_info.\r (load_equiv): Only free the equivalence if none of the members\r are used.\r\r2007-05-29  Daniel Franke  <franke.daniel@gmail.com>
 
        * gfortran.h: Renamed 'enum gfc_generic_isym_id' to 'enum gfc_isym_id',
        added missing GFC_ISYM_* enumerators, ordered alphabetically.
index 8a650385597efb85363f295beac36e52168aeb44..132de385860cb3c948e153cb028c988e3be18029 100644 (file)
@@ -189,7 +189,7 @@ static gfc_use_rename *gfc_rename_list;
 static pointer_info *pi_root;
 static int symbol_number;      /* Counter for assigning symbol numbers */
 
-/* Tells mio_expr_ref not to load unused equivalence members.  */
+/* Tells mio_expr_ref to make symbols for unused equivalence members.  */
 static bool in_load_equiv;
 
 
@@ -2234,9 +2234,25 @@ mio_symtree_ref (gfc_symtree **stp)
       require_atom (ATOM_INTEGER);
       p = get_integer (atom_int);
 
-      /* An unused equivalence member; bail out.  */
+      /* An unused equivalence member; make a symbol and a symtree
+        for it.  */
       if (in_load_equiv && p->u.rsym.symtree == NULL)
-       return;
+       {
+         /* Since this is not used, it must have a unique name.  */
+         p->u.rsym.symtree = get_unique_symtree (gfc_current_ns);
+
+         /* Make the symbol.  */
+         if (p->u.rsym.sym == NULL)
+           {
+             p->u.rsym.sym = gfc_new_symbol (p->u.rsym.true_name,
+                                             gfc_current_ns);
+             p->u.rsym.sym->module = gfc_get_string (p->u.rsym.module);
+           }
+
+         p->u.rsym.symtree->n.sym = p->u.rsym.sym;
+         p->u.rsym.symtree->n.sym->refs++;
+         p->u.rsym.referenced = 1;
+       }
       
       if (p->type == P_UNKNOWN)
        p->type = P_SYMBOL;
@@ -3206,13 +3222,13 @@ load_equiv (void)
        mio_expr (&tail->expr);
       }
 
-    /* Unused variables have no symtree.  */
-    unused = false;
+    /* Unused equivalence members have a unique name.  */
+    unused = true;
     for (eq = head; eq; eq = eq->eq)
       {
-       if (!eq->expr->symtree)
+       if (!check_unique_name (eq->expr->symtree->name))
          {
-           unused = true;
+           unused = false;
            break;
          }
       }
index 4ebf0027742024de40d1ca94f166749dad4a1da8..045a3369169543e907e1b5ed84dab9169a62c26d 100644 (file)
@@ -1,4 +1,4 @@
-2007-05-30  Russell Yanofsky <russ@yanofsky.org>
+2007-05-31  Paul Thomas  <pault@gcc.gnu.org>\r\r PR fortran/32103\r       * gfortran.dg/module_equivalence_3.f90: New test.\r\r2007-05-30  Russell Yanofsky <russ@yanofsky.org>
             Douglas Gregor <doug.gregor@gmail.com>
             Pedro Lamarao <pedro.lamarao@mndfck.org>
             Howard Hinnant <howard.hinnant@gmail.com>
diff --git a/gcc/testsuite/gfortran.dg/module_equivalence_3.f90 b/gcc/testsuite/gfortran.dg/module_equivalence_3.f90
new file mode 100644 (file)
index 0000000..d646f97
--- /dev/null
@@ -0,0 +1,38 @@
+! { dg-do run }
+! This checks the fix for PR32103 in which not using one member
+! of an equivalence group would cause all memory of the equivalence
+! to be lost and subsequent incorrect referencing of the remaining
+! members. 
+!
+! Contributed by Toon Moene <toon@moene.indiv.nluug.nl> 
+!
+module aap
+   real :: a(5) = (/1.0,2.0,3.0,4.0,5.0/) 
+   real :: b(3)
+   real :: d(5) = (/1.0,2.0,3.0,4.0,5.0/) 
+   equivalence (a(3),b(1))
+end module aap
+
+  use aap, only : b
+  call foo
+  call bar
+!  call foobar
+contains
+  subroutine foo
+    use aap, only : c=>b
+    if (any(c .ne. b)) call abort ()
+  end subroutine
+  subroutine bar
+    use aap, only : a
+    if (any(a(3:5) .ne. b)) call abort ()
+  end subroutine
+
+! Make sure that bad things do not happen if we do not USE a or b.
+
+  subroutine foobar
+    use aap, only : d
+    if (any(d(3:5) .ne. b)) call abort ()
+  end subroutine
+end
+
+! { dg-final { cleanup-modules "aap" } }