From patchwork Sun Dec 23 14:29:46 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 207976 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 E14102C0040 for ; Mon, 24 Dec 2012 01:30:03 +1100 (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=1356877805; h=Comment: DomainKey-Signature:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: References:In-Reply-To:Content-Type:Mailing-List:Precedence: List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=XPEvRgt+boCleE/xgBRD4oAsZmw=; b=nFFevGNf8fSqtQd Yk/5nXMxz0v8ud3IDk3EMCKdMJ8ri7+rlbl3VqoabVPfNSp48ToJU4Kt2taa5z3o bHm7vOLKqVE34Xl8870QODXOHjjIOHGq1e2cZD25fJ9E7fMAVL0A+e+kWlqIYeBh QRfdtgxuekVxZOxonpvtLdqzKTZU= 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:References:In-Reply-To:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=rrSh9Tgqs3IyBkDNMqUQes8iOdKCMl/m5uAKIaTw8cmi72DTaQkYmLd3KcLG5r H2nYc/Jc9Sz3PDW0TqBAdGMoTXIVMUebxQk+AydV8y5R9dYmJZHLRoSFS6BDVUZ0 H0GwZIfFOmcmLVc+03P9IHXSIdF4h3Ro37AyRUcVojRJs=; Received: (qmail 13687 invoked by alias); 23 Dec 2012 14:29:56 -0000 Received: (qmail 13668 invoked by uid 22791); 23 Dec 2012 14:29:55 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=AWL, BAYES_00, KHOP_THREADED, 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; Sun, 23 Dec 2012 14:29:48 +0000 Received: from archimedes.net-b.de (port-92-195-64-88.dynamic.qsc.de [92.195.64.88]) by mx01.qsc.de (Postfix) with ESMTP id BAF803CD42; Sun, 23 Dec 2012 15:29:46 +0100 (CET) Message-ID: <50D7155A.6040908@net-b.de> Date: Sun, 23 Dec 2012 15:29:46 +0100 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: gcc patches , gfortran Subject: Re: [Patch, Fortran] PR 54884 - Fix TREE_PUBLIC() issue with PRIVATE module procedures References: <50D49CB4.6090306@net-b.de> In-Reply-To: <50D49CB4.6090306@net-b.de> 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 Please ignore that patch. I found a much simpler way, which is a tiny patch and actually also works for the commented part of the test case of the previous patch (i.e. the missed-optimization bit). Namely, I now simply only tag all the symbols which are written to the .mod file. That way, there should be never a symbol which outside used (no wrong-code issues). As a positive side effect, a lot of code could be removed from resolve.c and interface.c. Build and regtested on x86-64-gnu-linux. OK for the trunk? Tobias Tobias Burnus wrote: > General background: Private module variables and module procedures can > be marked as TREE_PUBLIC()= 0, unless they are used in the > specification expression of the dummy argument or result variable of > public module procedures (or private module procedures in public > generic interfaces). 2012-12-23 Tobias Burnus PR fortran/54884 * module.c (write_symbol1_recursion): Set attr.public_use. * interface.c (check_sym_interfaces, check_uop_interfaces, gfc_check_interfaces): Remove attr.public_use code. * resolve.c (resolve_function, resolve_variable, resolve_typebound_procedure): Ditto. 2012-12-23 Tobias Burnus PR fortran/54884 * gfortran.dg/public_private_module_8.f90: New. diff --git a/gcc/fortran/interface.c b/gcc/fortran/interface.c index 908db74..b587d4a 100644 --- a/gcc/fortran/interface.c +++ b/gcc/fortran/interface.c @@ -1582,9 +1582,6 @@ check_sym_interfaces (gfc_symbol *sym) for (p = sym->generic; p; p = p->next) { - if (sym->attr.access != ACCESS_PRIVATE) - p->sym->attr.public_used = 1; - if (p->sym->attr.mod_proc && (p->sym->attr.if_source != IFSRC_DECL || p->sym->attr.procedure)) @@ -1610,16 +1607,11 @@ check_uop_interfaces (gfc_user_op *uop) char interface_name[100]; gfc_user_op *uop2; gfc_namespace *ns; - gfc_interface *p; sprintf (interface_name, "operator interface '%s'", uop->name); if (check_interface0 (uop->op, interface_name)) return; - if (uop->access != ACCESS_PRIVATE) - for (p = uop->op; p; p = p->next) - p->sym->attr.public_used = 1; - for (ns = gfc_current_ns; ns; ns = ns->parent) { uop2 = gfc_find_uop (uop->name, ns); @@ -1689,7 +1681,6 @@ void gfc_check_interfaces (gfc_namespace *ns) { gfc_namespace *old_ns, *ns2; - gfc_interface *p; char interface_name[100]; int i; @@ -1714,10 +1705,6 @@ gfc_check_interfaces (gfc_namespace *ns) if (check_interface0 (ns->op[i], interface_name)) continue; - for (p = ns->op[i]; p; p = p->next) - p->sym->attr.public_used = 1; - - if (ns->op[i]) gfc_check_operator_interface (ns->op[i]->sym, (gfc_intrinsic_op) i, ns->op[i]->where); diff --git a/gcc/fortran/module.c b/gcc/fortran/module.c index a797f24..e19c6d9 100644 --- a/gcc/fortran/module.c +++ b/gcc/fortran/module.c @@ -5238,6 +5238,7 @@ write_symbol1_recursion (sorted_pointer_info *sp) p1->u.wsym.state = WRITTEN; write_symbol (p1->integer, p1->u.wsym.sym); + p1->u.wsym.sym->attr.public_used = 1; write_symbol1_recursion (sp->right); } diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 77d3dc5..873400a 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -3129,12 +3129,6 @@ resolve_function (gfc_expr *expr) return FAILURE; } - if (sym && specification_expr && sym->attr.function - && gfc_current_ns->proc_name - && gfc_current_ns->proc_name->attr.flavor == FL_MODULE) - sym->attr.public_used = 1; - - /* Switch off assumed size checking and do this again for certain kinds of procedure, once the procedure itself is resolved. */ need_full_assumed_size++; @@ -5360,19 +5354,6 @@ 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 @@ -12146,7 +12127,6 @@ resolve_typebound_procedure (gfc_symtree* stree) gcc_assert (stree->n.tb->u.specific); proc = stree->n.tb->u.specific->n.sym; where = stree->n.tb->where; - proc->attr.public_used = 1; /* Default access should already be resolved from the parser. */ gcc_assert (stree->n.tb->access != ACCESS_UNKNOWN); diff --git a/gcc/testsuite/gfortran.dg/public_private_module_8.f90 b/gcc/testsuite/gfortran.dg/public_private_module_8.f90 new file mode 100644 index 0000000..bfc1b36 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/public_private_module_8.f90 @@ -0,0 +1,49 @@ +! { dg-do compile } +! { dg-options "-O2" } +! +! PR fortran/54884 +! +! Check that get_key_len is not optimized away as it +! is used in a publicly visible specification expression. +! + +module m + private + public :: foo + interface foo + module procedure bar + end interface foo +contains + pure function mylen() + integer :: mylen + mylen = 42 + end function mylen + pure function myotherlen() + integer :: myotherlen + myotherlen = 99 + end function myotherlen + subroutine bar(x) + character(len=mylen()) :: x + character :: z2(myotherlen()) + call internal(x) + block + character(len=myotherlen()) :: z + z = "abc" + x(1:5) = z + end block + x(6:10) = intern_func() + contains + function intern_func() + character(len=myotherlen()) :: intern_func + intern_func = "zuzu" + end function intern_func + subroutine internal(y) + character(len=myotherlen()) :: y + y = "abc" + end subroutine internal + end subroutine bar +end module m + +! { dg-final { scan-assembler-not "__m_MOD_myotherlen" } } +! { dg-final { scan-assembler "__m_MOD_bar" } } +! { dg-final { scan-assembler "__m_MOD_mylen" } }