From patchwork Sun Jul 14 19:17:29 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 258906 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 56C0C2C0176 for ; Mon, 15 Jul 2013 05:17:56 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; q=dns; s=default; b=IUgGSWQXU4khHjg/z jfzubta25YVvV9Xlfswx/XmqOQ72sKJCUuPzVvzWo8JNGleYoe9Qr59Wg2pmjarm hlp2YImShujVUBloXn5WaAm208TU0OPfEOQ11W+gfwR8W7jh80DUxx8QFSGl0At4 S5c+GMeQOvb2DCw5tv/2l6jSDU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; s=default; bh=Sb6eiKLtl5LzdeMCK8RR+Dw PzRU=; b=yN3Mn/ggYn7gRvu63kj2ldxpZIzTj88dqvoKP1DM0MEKcNzJgN8wmJu Pzt2gB3zHGH+Lv/IEe4kXxeMU4/3fKHxjA3wYZxgA4Pnfqv5RyJihMm2RAK7VWl8 3HFlG+OolENzva/kZtHoKxiN65n4rU6pK8JB02GL2af9T+j4ITq8= Received: (qmail 6174 invoked by alias); 14 Jul 2013 19:17:44 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 6154 invoked by uid 89); 14 Jul 2013 19:17:43 -0000 X-Spam-SWARE-Status: No, score=-1.1 required=5.0 tests=AWL, BAYES_50, KHOP_RCVD_UNTRUST, KHOP_THREADED, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_NO, RDNS_NONE autolearn=ham version=3.3.1 X-Spam-User: qpsmtpd, 2 recipients Received: from Unknown (HELO cc-smtpout2.netcologne.de) (89.1.8.212) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Sun, 14 Jul 2013 19:17:41 +0000 Received: from cc-smtpin2.netcologne.de (cc-smtpin2.netcologne.de [89.1.8.202]) by cc-smtpout2.netcologne.de (Postfix) with ESMTP id 865BE11FF9; Sun, 14 Jul 2013 21:17:33 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by cc-smtpin2.netcologne.de (Postfix) with ESMTP id 7411611D79; Sun, 14 Jul 2013 21:17:33 +0200 (CEST) Received: from [87.79.199.41] (helo=cc-smtpin2.netcologne.de) by localhost with ESMTP (eXpurgate 4.0.0) (envelope-from ) id 51e2f94d-053f-7f0000012729-7f00000198ff-1 for ; Sun, 14 Jul 2013 21:17:33 +0200 Received: from [192.168.0.110] (xdsl-87-79-199-41.netcologne.de [87.79.199.41]) by cc-smtpin2.netcologne.de (Postfix) with ESMTPSA; Sun, 14 Jul 2013 21:17:31 +0200 (CEST) Message-ID: <51E2F949.20008@netcologne.de> Date: Sun, 14 Jul 2013 21:17:29 +0200 From: Thomas Koenig User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 MIME-Version: 1.0 To: Tobias Burnus CC: "fortran@gcc.gnu.org" , gcc-patches Subject: Re: [patch, fortran] PR 52669, warn about unused PRIVATE module variables References: <51E06FFE.4070606@netcologne.de> <51E0E2F6.5010703@net-b.de> In-Reply-To: <51E0E2F6.5010703@net-b.de> X-Virus-Found: No 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 Tobias Burnus 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 PR fortran/52669 * fortran.dg/module_variable_1.f90: New test. * fortran.dg/module_variable_2.f90: New test. Index: fortran/ChangeLog =================================================================== --- fortran/ChangeLog (Revision 200949) +++ fortran/ChangeLog (Arbeitskopie) @@ -1,3 +1,13 @@ +2013-07-14 Thomas Koenig + Tobias Burnus + + 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 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 + + PR fortran/52669 + * fortran.dg/module_variable_1.f90: New test. + * fortran.dg/module_variable_2.f90: New test. + 2013-07-14 Marc Glisse * 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