From patchwork Thu May 3 18:41:22 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 156761 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]) by ozlabs.org (Postfix) with SMTP id 463AFB6F6E for ; Fri, 4 May 2012 04:41:45 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1336675306; h=Comment: DomainKey-Signature:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=tzvl/uP rR3/olQnaiglJ/T35oj0=; b=GQP2whZK8x8n3F2ZXJ/No+i3il7y1ZQhvOpFAVS YXafqZ4PJO58V+p0u6/T6Foh6vOqkTatV89nt0oTfDlBTX7d5Vjgb1uUIpXN68wZ a6G8L8tcpj2MrwufqKrFZQhzDQMevK2o308dNFuO+Egk8zgTkPAZdl5rqGRJZm3v w5T8= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=YWfQEq3q8WO4NSij+0q2Fc5sgogiD3vJwD1gsG/oLIUA7mLrsQguCyTviZlJDf 7y4spmzVYbyC7s4pgXTAn8IBr64am9g1OMzc2Yxq/L3OaOWJOAcQ41e6YIBFe3b0 QHrSOK2xaNlfsNAQRo05nfHNUz8QvUslpTuf4vBXrVt+8=; Received: (qmail 31402 invoked by alias); 3 May 2012 18:41:39 -0000 Received: (qmail 31388 invoked by uid 22791); 3 May 2012 18:41:38 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from mx01.qsc.de (HELO mx01.qsc.de) (213.148.129.14) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 03 May 2012 18:41:25 +0000 Received: from [192.168.178.22] (port-92-204-82-207.dynamic.qsc.de [92.204.82.207]) by mx01.qsc.de (Postfix) with ESMTP id A28933CFE2; Thu, 3 May 2012 20:41:22 +0200 (CEST) Message-ID: <4FA2D152.8010807@net-b.de> Date: Thu, 03 May 2012 20:41:22 +0200 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120328 Thunderbird/11.0.1 MIME-Version: 1.0 To: gcc patches , gfortran Subject: [Patch, Fortran] PR53175 - Fix another fallout of the TREE_PUBLIC=0 module variable patch 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 A PRIVATE module variable, which is used in the specification expression of a function result variable cannot be TREE_PUBLIC()=0, unless the function itself is PRIVATE and also not accessible via type-bound procedures or a generic name. (The issue is gfortran specific as most compilers do not seem to save the specification expression in the .mod file.) Build and regtested on x86-64-linux. OK for the trunk? Tobias 2012-05-03 Tobias Burnus PR fortran/53175 * resolve.c (resolve_variable): Set public_used if a private module variable is used in a (public) specification expression. * trans-decl.c (gfc_finish_var_decl): Mark those TREE_PUBLIC. 2012-05-03 Tobias Burnus PR fortran/53175 gfortran.dg/public_private_module_5.f90: New. diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 57da577..e15d6e1 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -5124,6 +5124,19 @@ resolve_variable (gfc_expr *e) if (check_assumed_size_reference (sym, e)) return FAILURE; + /* If a PRIVATE variable is used in the specification expression of the + result variable, it might be accessed from outside the module and can + thus not be TREE_PUBLIC() = 0. + TODO: sym->attr.public_used only has to be set for the result variable's + type-parameter expression and not for dummies or automatic variables. + Additionally, it only has to be set if the function is either PUBLIC or + used in a generic interface or TBP; unfortunately, + proc_name->attr.public_used can get set at a later stage. */ + if (specification_expr && sym->attr.access == ACCESS_PRIVATE + && !sym->attr.function && !sym->attr.use_assoc + && gfc_current_ns->proc_name && gfc_current_ns->proc_name->attr.function) + sym->attr.public_used = 1; + /* Deal with forward references to entries during resolve_code, to satisfy, at least partially, 12.5.2.5. */ if (gfc_current_ns->entries diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index d6c090e..9196f0a 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -565,7 +565,7 @@ 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_PRIVATE) + if (sym->attr.access != ACCESS_PRIVATE || sym->attr.public_used) TREE_PUBLIC (decl) = 1; TREE_STATIC (decl) = 1; } --- /dev/null 2012-04-23 08:17:57.683771451 +0200 +++ gcc/gcc/testsuite/gfortran.dg/public_private_module_5.f90 2012-05-03 15:11:54.000000000 +0200 @@ -0,0 +1,40 @@ +! { dg-do compile } +! { dg-options "-O3" } +! +! PR fortran/53175 +! + +MODULE ENERGY_FUNCTION + IMPLICIT NONE + + TYPE PARAM + PRIVATE + INTEGER :: WHICH_VECTOR + END TYPE PARAM + + INTEGER, PRIVATE :: DIM2 + INTEGER, PRIVATE :: DIM5 + + private :: specific + interface gen + module procedure specific + end interface gen + + CONTAINS + + FUNCTION ENERGY_FUNCTION_CURRENT_ARGS() + INTEGER, DIMENSION(DIM2) :: ENERGY_FUNCTION_CURRENT_ARGS + END FUNCTION ENERGY_FUNCTION_CURRENT_ARGS + + FUNCTION ENERGY_FUNCTION_GET_PARAMS() + TYPE(PARAM), DIMENSION(DIM2) :: ENERGY_FUNCTION_GET_PARAMS + END FUNCTION ENERGY_FUNCTION_GET_PARAMS + + function specific() + character(len=dim5) :: specific + end function specific +END MODULE ENERGY_FUNCTION + +! { dg-final { scan-assembler "__energy_function_MOD_dim2" } } +! { dg-final { scan-assembler "__energy_function_MOD_dim5" } } +