From patchwork Thu Dec 29 09:53:32 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 133535 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 0EB43B6FB4 for ; Thu, 29 Dec 2011 20:54:00 +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=1325757241; h=Comment: DomainKey-Signature:Received: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=5uyE8ml h+VvPvC9IybDsqlLOJ24=; b=yvakSSVvZlQkTHvLARzQAwsP04U6egZRnpIWTXm kdo9SkNixy97zt8hStk3mJm08jQnXOwZhO/xg2Owsw4awVttPunqaCFrv8RQLUd6 Qndc+vZfhmgeCJaSGhidSq9lhSPl2O2v7xEUDUA8jAv8pwTW9s9X3WWcOp640tpX E+ZQ= 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: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=u4BgUbv1ZDN2cr40K4XvTgQSh5LlTuA2LjR9q/r8JtOyMYuiNnGpR20HMoI7+2 0W8qJq1CJCY1MuON2mGWS8yiwxhX6WMEgcDoCGez3ejt2PlrdAwR75NVwRLmsuz4 WRaeRB6yakWOlVSEMhn1iEN4OWS89/43kYz2xO93Rbym0=; Received: (qmail 31666 invoked by alias); 29 Dec 2011 09:53:52 -0000 Received: (qmail 31649 invoked by uid 22791); 29 Dec 2011 09:53:50 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from cc-smtpout3.netcologne.de (HELO cc-smtpout3.netcologne.de) (89.1.8.213) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 29 Dec 2011 09:53:37 +0000 Received: from cc-smtpin1.netcologne.de (cc-smtpin1.netcologne.de [89.1.8.201]) by cc-smtpout3.netcologne.de (Postfix) with ESMTP id BF992130C1; Thu, 29 Dec 2011 10:53:34 +0100 (CET) Received: from [192.168.0.106] (xdsl-78-35-145-162.netcologne.de [78.35.145.162]) by cc-smtpin1.netcologne.de (Postfix) with ESMTPSA id 98CDA11DBB; Thu, 29 Dec 2011 10:53:33 +0100 (CET) Message-ID: <4EFC389C.3040704@netcologne.de> Date: Thu, 29 Dec 2011 10:53:32 +0100 From: Thomas Koenig User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.2.17) Gecko/20110414 SUSE/3.1.10 Thunderbird/3.1.10 MIME-Version: 1.0 To: "fortran@gcc.gnu.org" , gcc-patches Subject: [patch, fortran] Fix PR 51502 - wrong implicit pure 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 Hello world, the attached patch fixes PR 51502, where we wrongly recognized a procedure as implicit pure when we were assigning to a module variable within a block. This is a potential cause for wrong-code regressions (although no actual test case exists). For the test case, I had to scan for the absence of a string, which is why I introduced a new function for the testsuite. Regression-tested. OK for trunk and (after some time) for 4.6? Thomas 2011-12-29 Thomas König PR fortran/51502 * expr.c (gfc_check_vardef_context): When determining implicit pure status, also check for variable definition context. Walk up namespaces until a procedure is found to reset the implict pure attribute. * resolve.c (gfc_implicit_pure): Walk up namespaces until a procedure is found. 2011-12-29 Thomas König PR fortran/51502 * lib/gcc-dg.exp (scan-module-absence): New function. * gfortran.dg/implicit_pure_2.f90: New test. ! { dg-do compile } ! PR 51502 - this was wrongly detected to be implicit pure. module m integer :: i contains subroutine foo(x) integer, intent(inout) :: x outer: block block i = 5 end block end block outer end subroutine foo end module m ! { dg-final { scan-module-absence "m" "IMPLICIT_PURE" } } ! { dg-final { cleanup-modules "m" } } Index: fortran/expr.c =================================================================== --- fortran/expr.c (Revision 182719) +++ fortran/expr.c (Arbeitskopie) @@ -4690,9 +4690,24 @@ gfc_check_vardef_context (gfc_expr* e, bool pointe return FAILURE; } - if (!pointer && gfc_implicit_pure (NULL) && gfc_impure_variable (sym)) - gfc_current_ns->proc_name->attr.implicit_pure = 0; + if (!pointer && context && gfc_implicit_pure (NULL) + && gfc_impure_variable (sym)) + { + gfc_namespace *ns; + gfc_symbol *sym; + for (ns = gfc_current_ns; ns; ns = ns->parent) + { + sym = ns->proc_name; + if (sym == NULL) + break; + if (sym->attr.flavor == FL_PROCEDURE) + { + sym->attr.implicit_pure = 0; + break; + } + } + } /* Check variable definition context for associate-names. */ if (!pointer && sym->assoc) { Index: fortran/resolve.c =================================================================== --- fortran/resolve.c (Revision 182719) +++ fortran/resolve.c (Arbeitskopie) @@ -13103,24 +13103,25 @@ gfc_pure (gfc_symbol *sym) int gfc_implicit_pure (gfc_symbol *sym) { - symbol_attribute attr; + gfc_namespace *ns; if (sym == NULL) { - /* Check if the current namespace is implicit_pure. */ - sym = gfc_current_ns->proc_name; - if (sym == NULL) - return 0; - attr = sym->attr; - if (attr.flavor == FL_PROCEDURE - && attr.implicit_pure && !attr.pure) - return 1; - return 0; + /* Check if the current procedure is implicit_pure. Walk up + the procedure list until we find a procedure. */ + for (ns = gfc_current_ns; ns; ns = ns->parent) + { + sym = ns->proc_name; + if (sym == NULL) + return 0; + + if (sym->attr.flavor == FL_PROCEDURE) + break; + } } - - attr = sym->attr; - - return attr.flavor == FL_PROCEDURE && attr.implicit_pure && !attr.pure; + + return sym->attr.flavor == FL_PROCEDURE && sym->attr.implicit_pure + && !sym->attr.pure; } Index: testsuite/lib/gcc-dg.exp =================================================================== --- testsuite/lib/gcc-dg.exp (Revision 182430) +++ testsuite/lib/gcc-dg.exp (Arbeitskopie) @@ -598,6 +598,24 @@ proc scan-module { args } { } } +# Scan Fortran modules for absence of a given regexp. +# +# Argument 0 is the module name +# Argument 1 is the regexp to match +proc scan-module-absence { args } { + set modfilename [string tolower [lindex $args 0]].mod + set fd [open $modfilename r] + set text [read $fd] + close $fd + + upvar 2 name testcase + if [regexp -- [lindex $args 1] $text] { + fail "$testcase scan-module [lindex $args 1]" + } else { + pass "$testcase scan-module [lindex $args 1]" + } +} + # Verify that the compiler output file exists, invoked via dg-final. proc output-exists { args } { # Process an optional target or xfail list.