OSDN Git Service

2012-04-07 Thomas Koenig <tkoenig@gcc.gnu.org>
authortkoenig <tkoenig@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 7 Apr 2012 19:58:43 +0000 (19:58 +0000)
committertkoenig <tkoenig@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 7 Apr 2012 19:58:43 +0000 (19:58 +0000)
PR fortran/52668
Backport from trunk
* module.c:  Only mark symbols as use_only if they have been
imported via an only list.

2012-04-07  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR fortran/52668
Backport from trunk
* gfortran.dg/use_only_6.f90: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_7-branch@186214 138bc75d-0d04-0410-961f-82ee72b054a4

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

index 816d424..897b012 100644 (file)
@@ -1,3 +1,10 @@
+2012-04-07  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR fortran/52668
+       Backport from trunk
+       * module.c:  Only mark symbols as use_only if they have been
+       imported via an only list.
+
 2012-03-22  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/52452
index 5e0f26e..e363177 100644 (file)
@@ -4388,9 +4388,24 @@ load_needed (pointer_info *p)
 
   /* Mark as only or rename for later diagnosis for explicitly imported
      but not used warnings; don't mark internal symbols such as __vtab,
-     __def_init etc.  */
+     __def_init etc. Only mark them if they have been explicitly loaded.  */
+
   if (only_flag && sym->name[0] != '_' && sym->name[1] != '_')
-    sym->attr.use_only = 1;
+    {
+      gfc_use_rename *u;
+
+      /* Search the use/rename list for the variable; if the variable is
+        found, mark it.  */
+      for (u = gfc_rename_list; u; u = u->next)
+       {
+         if (strcmp (u->use_name, sym->name) == 0)
+           {
+             sym->attr.use_only = 1;
+             break;
+           }
+       }
+    }
+
   if (p->u.rsym.renamed)
     sym->attr.use_rename = 1;
 
index 8ed3e2d..fcbbe12 100644 (file)
@@ -1,3 +1,9 @@
+2012-04-07  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR fortran/52668
+       Backport from trunk
+       * gfortran.dg/use_only_6.f90: New test.
+
 2012-04-06  Mike Stump  <mikestump@comcast.net>
 
        PR testsuite/50722
diff --git a/gcc/testsuite/gfortran.dg/use_only_6.f90 b/gcc/testsuite/gfortran.dg/use_only_6.f90
new file mode 100644 (file)
index 0000000..c2b3bfd
--- /dev/null
@@ -0,0 +1,14 @@
+! { dg-do compile }
+! PR 52668 - there used to be a bogus warning about not using b.
+! Original test case by Arnaud Desitter.
+module mm
+  integer :: a, b
+  common /mm1/ a, b
+end module mm
+
+subroutine aa()
+  use mm, only: a
+  implicit none
+  a = 1
+end subroutine aa
+! { dg-final { cleanup-modules "mm" } }