From patchwork Sun Mar 25 09:28:20 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [fortran] Fix PR 52668, bogus warning for only list Date: Sat, 24 Mar 2012 23:28:20 -0000 From: Thomas Koenig X-Patchwork-Id: 148554 Message-Id: <4F6EE534.8070502@netcologne.de> To: "fortran@gcc.gnu.org" , gcc-patches Hello world, this fixes a 4.7/4.8 regression with a bogus warning for variables which were excluded from being imported by "use, only" if they were in a common block inside the module. Regression-tested. OK for trunk and for 4.7 after a few days? Thomas 2012-03-25 Thomas Koenig PR fortran/52668 * module.c: Only mark symbols as use_only if they have been imported via an only list. 2012-03-25 Thomas Koenig PR fortran/52668 * gfortran.dg/use_only_6.f90: New test. ! { 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" } } Index: module.c =================================================================== --- module.c (Revision 184854) +++ module.c (Arbeitskopie) @@ -4389,9 +4389,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;