[prev in list] [next in list] [prev in thread] [next in thread]
List: gcc-patches
Subject: Re: [patch, fortran] PR 52669, warn about unused PRIVATE module variables
From: Thomas Koenig <tkoenig () netcologne ! de>
Date: 2013-07-14 19:17:29
Message-ID: 51E2F949.20008 () netcologne ! de
[Download RAW message or body]
Hi Tobias,
> 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.
Taken care of in the attached patch, the way you suggested works.
Committed as rev. 200950.
Thanks for the review!
Thomas
2013-07-14 Thomas Koenig <tkoenig@gcc.gnu.org>
Tobias Burnus <burnus@gcc.gnu.org>
PR fortran/52669
* trans-decl.c (gfc_finish_var_decl): Move setting of
PRIVATE for a module variable if the module has a private
default or -fmodule-private is given to...
(gfc_create_module_variable): here. Optionally
warn about private module variable which is not used.
2013-07-14 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/52669
* fortran.dg/module_variable_1.f90: New test.
* fortran.dg/module_variable_2.f90: New test.
["module_variable_1.f90" (text/x-fortran)]
! { dg-do compile }
! { dg-options "-Wall" }
module foo
integer, private :: i ! { dg-warning "Unused PRIVATE" }
integer, private :: j = 0
contains
subroutine bar
j = j + 1
end subroutine bar
end module foo
module bar
private
integer :: i ! { dg-warning "Unused PRIVATE" }
end module bar
["module_variable_2.f90" (text/x-fortran)]
! { dg-do compile }
! { dg-options "-Wall -fmodule-private" }
module bar
integer :: i ! { dg-warning "Unused PRIVATE" }
end module bar
["p3.diff" (text/x-patch)]
Index: fortran/ChangeLog
===================================================================
--- fortran/ChangeLog (Revision 200949)
+++ fortran/ChangeLog (Arbeitskopie)
@@ -1,3 +1,13 @@
+2013-07-14 Thomas Koenig <tkoenig@gcc.gnu.org>
+ Tobias Burnus <burnus@gcc.gnu.org>
+
+ PR fortran/52669
+ * trans-decl.c (gfc_finish_var_decl): Move setting of
+ PRIVATE for a module variable if the module has a private
+ default or -fmodule-private is given to...
+ (gfc_create_module_variable): here. Optionally
+ warn about private module variable which is not used.
+
2013-07-08 Tobias Burnus <burnus@net-b.de>
PR fortran/57834
Index: fortran/trans-decl.c
===================================================================
--- fortran/trans-decl.c (Revision 200949)
+++ fortran/trans-decl.c (Arbeitskopie)
@@ -559,12 +559,6 @@ gfc_finish_var_decl (tree decl, gfc_symbol * sym)
{
/* TODO: Don't set sym->module for result or dummy variables. */
gcc_assert (current_function_decl == NULL_TREE || sym->result == sym);
- /* This is the declaration of a module variable. */
- 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;
if (sym->attr.access != ACCESS_PRIVATE || sym->attr.public_used)
TREE_PUBLIC (decl) = 1;
@@ -4212,6 +4206,18 @@ gfc_create_module_variable (gfc_symbol * sym)
internal_error ("backend decl for module variable %s already exists",
sym->name);
+ if (sym->module && !sym->attr.result && !sym->attr.dummy
+ && (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;
+
+ 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. */
Index: testsuite/ChangeLog
===================================================================
--- testsuite/ChangeLog (Revision 200949)
+++ testsuite/ChangeLog (Arbeitskopie)
@@ -1,3 +1,9 @@
+2013-07-14 Thomas Koenig <tkoenig@gcc.gnu.org>
+
+ PR fortran/52669
+ * fortran.dg/module_variable_1.f90: New test.
+ * fortran.dg/module_variable_2.f90: New test.
+
2013-07-14 Marc Glisse <marc.glisse@inria.fr>
* g++.dg/ext/vector19.C: Adapt.
Index: testsuite/gfortran.dg/module_variable_1.f90
===================================================================
--- testsuite/gfortran.dg/module_variable_1.f90 (Revision 0)
+++ testsuite/gfortran.dg/module_variable_1.f90 (Arbeitskopie)
@@ -0,0 +1,15 @@
+! { dg-do compile }
+! { dg-options "-Wall" }
+module foo
+ integer, private :: i ! { dg-warning "Unused PRIVATE" }
+ integer, private :: j = 0
+contains
+ subroutine bar
+ j = j + 1
+ end subroutine bar
+end module foo
+
+module bar
+ private
+ integer :: i ! { dg-warning "Unused PRIVATE" }
+end module bar
Index: testsuite/gfortran.dg/module_variable_2.f90
===================================================================
--- testsuite/gfortran.dg/module_variable_2.f90 (Revision 0)
+++ testsuite/gfortran.dg/module_variable_2.f90 (Arbeitskopie)
@@ -0,0 +1,6 @@
+! { dg-do compile }
+! { dg-options "-Wall -fmodule-private" }
+
+module bar
+ integer :: i ! { dg-warning "Unused PRIVATE" }
+end module bar
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic