diff mbox

[fortran] PR 52669, warn about unused PRIVATE module variables

Message ID 51E06FFE.4070606@netcologne.de
State New
Headers show

Commit Message

Thomas Koenig July 12, 2013, 9:07 p.m. UTC
Hello world,

here is a rather self-evident patch for PR 52669.

Regression-tested. OK for trunk?

	Thomas


2013-07-12  Thomas Koenig  <tkoenig@gcc.gnu.org>

         PR fortran/52669
         * trans-decl.c (gfc_create_module_variable):  Optionally
         warn about private module variable which is not used.

2013-07-12  Thomas Koenig  <tkoenig@gcc.gnu.org>

         PR fortran/52669
         * fortran.dg/module_variable_1.f90:  New test.

Comments

Tobias Burnus July 13, 2013, 5:17 a.m. UTC | #1
Am 12.07.2013 23:07, Thomas Koenig wrote:
> here is a rather self-evident patch for PR 52669.
> Regression-tested. OK for trunk?

I think you should also handle:
   module m
      private
      integer :: k
   end module m

and
   module m2
      integer :: ll
   end module m2
when compiled with -fmodule-private.

I think that's not yet handled by your code. It is probably sufficient 
to move the following code (in the same function) up before your check:

       if (sym->attr.access == ACCESS_UNKNOWN
           && (sym->ns->default_access == ACCESS_PRIVATE
               || (sym->ns->default_access == ACCESS_UNKNOWN
                   && gfc_option.flag_module_private)))
         sym->attr.access = ACCESS_PRIVATE;


Otherwise, it looks okay to me.

Tobias

PS: We will have to change the check when submodules are supported. But 
it is detectable in a module whether it is used as submodule; one can 
even handle as additional special case that there is a submodule, but it 
is in the same file.


> 2013-07-12 Thomas Koenig  <tkoenig@gcc.gnu.org>
>
>         PR fortran/52669
>         * trans-decl.c (gfc_create_module_variable):  Optionally
>         warn about private module variable which is not used.
>
> 2013-07-12  Thomas Koenig  <tkoenig@gcc.gnu.org>
>
>         PR fortran/52669
>         * fortran.dg/module_variable_1.f90:  New test.
diff mbox

Patch

Index: trans-decl.c
===================================================================
--- trans-decl.c	(Revision 200743)
+++ trans-decl.c	(Arbeitskopie)
@@ -4212,6 +4212,11 @@  gfc_create_module_variable (gfc_symbol * sym)
     internal_error ("backend decl for module variable %s already exists",
 		    sym->name);
 
+  if (warn_unused_variable && !sym->attr.referenced
+      && sym->attr.access == ACCESS_PRIVATE)
+    gfc_warning ("Unused PRIVATE module variable '%s' declared at %L",
+		 sym->name, &sym->declared_at);
+
   /* We always want module variables to be created.  */
   sym->attr.referenced = 1;
   /* Create the decl.  */