From 631cfe30838acc834c38a7ce89339e144f49000f Mon Sep 17 00:00:00 2001 From: Thomas Koenig Date: Fri, 6 Apr 2012 18:31:11 +0000 Subject: [PATCH] re PR fortran/52668 (Incorrect unused warning for USE associating variable in common block) 2012-04-06 Thomas Koenig PR fortran/52668 * module.c: Only mark symbols as use_only if they have been imported via an only list. 2012-04-06 Thomas Koenig PR fortran/52668 * gfortran.dg/use_only_6.f90: New test. From-SVN: r186199 --- gcc/fortran/ChangeLog | 8 +++++++- gcc/fortran/module.c | 19 +++++++++++++++++-- gcc/testsuite/ChangeLog | 9 +++++++++ gcc/testsuite/gfortran.dg/use_only_6.f90 | 13 +++++++++++++ 4 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/use_only_6.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 4a79df8d1ef..050f25e15fd 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2012-04-06 Thomas Koenig + + PR fortran/52668 + * module.c: Only mark symbols as use_only if they have been + imported via an only list. + 2012-03-28 Paul Thomas Tobias Burnus @@ -5,7 +11,7 @@ * match.c (gfc_match_allocate, gfc_match_deallocate): Change "not.. or" to "neither.. nor". * parse.c (decode_specification_statement): Correct error in - chpice of matching function for "allocatable". + chpice of matching function for "allocatable". 2012-03-23 Janne Blomqvist diff --git a/gcc/fortran/module.c b/gcc/fortran/module.c index 05ed2a2b9fd..60a74cacca4 100644 --- a/gcc/fortran/module.c +++ b/gcc/fortran/module.c @@ -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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index cd043f2c12d..3d6756089f5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2012-04-06 Thomas Koenig + + PR fortran/52668 + * gfortran.dg/use_only_6.f90: New test. + +2012-04-06 Thomas Koenig + + PR fortran/52668 + * gfortran.dg/use_only_6.f90: New test. 2012-04-06 Mike Stump 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 index 00000000000..bc15fdb065a --- /dev/null +++ b/gcc/testsuite/gfortran.dg/use_only_6.f90 @@ -0,0 +1,13 @@ +! { 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