From patchwork Sun Aug 31 22:28:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 384598 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 7F3E6140119 for ; Mon, 1 Sep 2014 08:28:55 +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:subject:references :in-reply-to:content-type; q=dns; s=default; b=cLVvWtZ9OrllCz1PU 0j4179Fllnc3nc/OyZvUH7C4E0L1RdScau/gVh2BckNN43knWIjzVNXRh+GJUoH8 91JlyVxXTqAMUTdycxAT2GN1EEkehon8hRl/nY541ZbKviCt+V+7remAjTX3mNVL lodZ4sPlTKjEUpY7V9xQwOtxX4= 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:subject:references :in-reply-to:content-type; s=default; bh=0mjS4IjhvD3HCdZuoNFoBcw oL2Q=; b=rezaI3BOqtzIkWSEYddfdkM0O3S/UH/n4G15ywjffvPCB0ArK0bxRYX /dhbHAVjkFGKQUyjlKOR44L/qeo/KnImGj0aU95bObV5Ue+AM+H075RD1A7hMzqr Z6Vtias5dnQF4wYmV5J3pNUigaKXA4LNsxlxCdr+s8bHVAP/5jOs= Received: (qmail 20303 invoked by alias); 31 Aug 2014 22:28:47 -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 20275 invoked by uid 89); 31 Aug 2014 22:28:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.0 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx02.qsc.de Received: from mx02.qsc.de (HELO mx02.qsc.de) (213.148.130.14) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Sun, 31 Aug 2014 22:28:43 +0000 Received: from tux.net-b.de (port-92-194-89-213.dynamic.qsc.de [92.194.89.213]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx02.qsc.de (Postfix) with ESMTPSA id BEBDB24A4F; Mon, 1 Sep 2014 00:28:39 +0200 (CEST) Message-ID: <5403A197.3020400@net-b.de> Date: Mon, 01 Sep 2014 00:28:39 +0200 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.7.0 MIME-Version: 1.0 To: Fritz Reese , fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: Re: [PATCH, Fortran] -fno-automatic with -finit-local prevents initialization of automatics in recursive functions References: In-Reply-To: Fritz Reese wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62309 > > It seems with gcc-4.8.3 -fno-automatic prevents initializers from > being applied to automatic variables. [...] > According to gfortran's manual page, -fno-automatic should "Treat each > program unit (except those marked as RECURSIVE) as if the "SAVE" > statement were specified for every local variable [...]". As far as I > can tell, -finit-local-zero should still initialize automatic > variables in RECURSIVE functions. > > I believe this is a simple fix; to actually follow the specification > set forth in the man page, don't treat symbols in a RECURSIVE > namespace as if they are saved in resolve.c > (apply_default_init_local): Thanks for the patch. I think it qualifies as obvious. But note for potential future contributions that for nontrivial contributions a copyright assignment with the FSF is required: https://gcc.gnu.org/contribute.html (Tiny nit: 8 spaces are replaced by a tab.) I initially thought that one had to be more careful because of BLOCK, but the RECURSIVE is passed on those namespaces, hence, the patch works fine. I have extended the test case to cover that part as well. I have now committed the attached version of the patch to the trunk (GCC 5) as Rev. 214771. Tobias (Side remark: I think it is bad style to rely on -finit-local with new code - and RECURSIVE is new since Fortran 90) code.) > 2014-08-29 Fritz Reese > > * resolve.c (apply_default_init_local): Don't treat variables in > RECURSIVE units as saved. Index: gcc/fortran/ChangeLog =================================================================== --- gcc/fortran/ChangeLog (Revision 214770) +++ gcc/fortran/ChangeLog (Arbeitskopie) @@ -1,3 +1,9 @@ +2014-08-31 Fritz Reese + + PR fortran/62309 + * resolve.c (apply_default_init_local): Don't treat variables + in RECURSIVE procedures as saved. + 2014-08-31 Tobias Burnus * trans-decl.c (gfc_build_builtin_function_decls): Add Index: gcc/fortran/resolve.c =================================================================== --- gcc/fortran/resolve.c (Revision 214770) +++ gcc/fortran/resolve.c (Arbeitskopie) @@ -10780,6 +10780,7 @@ apply_default_init_local (gfc_symbol *sym) result variable, which are also nonstatic. */ if (sym->attr.save || sym->ns->save_all || (gfc_option.flag_max_stack_var_size == 0 && !sym->attr.result + && !sym->ns->proc_name->attr.recursive && (!sym->attr.dimension || !is_non_constant_shape_array (sym)))) { /* Don't clobber an existing initializer! */ Index: gcc/testsuite/ChangeLog =================================================================== --- gcc/testsuite/ChangeLog (Revision 214770) +++ gcc/testsuite/ChangeLog (Arbeitskopie) @@ -1,3 +1,9 @@ +2014-08-31 Fritz Reese + Tobias Burnus + + PR fortran/62309 + * gcc/testsuite/gfortran.dg/auto_save_2.f90: New. + 2014-08-31 Tobias Burnus * gfortran.dg/coarray_lib_comm_1.f90: New. Index: gcc/testsuite/gfortran.dg/auto_save_2.f90 =================================================================== --- gcc/testsuite/gfortran.dg/auto_save_2.f90 (Revision 0) +++ gcc/testsuite/gfortran.dg/auto_save_2.f90 (Arbeitskopie) @@ -0,0 +1,84 @@ +! { dg-do run } +! { dg-options "-fno-automatic -finit-local-zero -fdump-tree-original" } +! +! PR fortran/62309 +! +! Make sure variables are saved with -fno-automatic except in +! functions marked RECURSIVE, and that they are still initialized with +! -finit-local-zero. +! + +function f (x) +implicit none + integer f, x + integer a ! should be SAVEd + a = a + x ! should increment by y every time + f = a + return +endfunction + +function f2 (x) +implicit none + integer f2, x + block + named: block + block + integer a ! should be SAVEd + a = a + x ! should increment by y every time + f2 = a + end block + end block named + end block + return +endfunction + +recursive function g (x) +implicit none + integer g, x + integer b ! should be automatic + b = b + x ! should be set to y every time + g = b + return +endfunction + +recursive function g2 (x) +implicit none + integer g2, x + block + named: block + block + integer b ! should be automatic + b = b + x ! should be set to y every time + g2 = b + end block + end block named + end block + return +endfunction + +implicit none +integer f, f2, g, g2 + +! Should return static value of a; accumulates y +if ( f(3) .ne. 3 ) call abort () +if ( f(4) .ne. 7 ) call abort () +if ( f(2) .ne. 9 ) call abort () + +if ( f2(3) .ne. 3 ) call abort () +if ( f2(4) .ne. 7 ) call abort () +if ( f2(2) .ne. 9 ) call abort () + +! Should return automatic value of a; equal to y each time +if ( g(3) .ne. 3 ) call abort () +if ( g(4) .ne. 4 ) call abort () +if ( g(2) .ne. 2 ) call abort () + +if ( g2(3) .ne. 3 ) call abort () +if ( g2(4) .ne. 4 ) call abort () +if ( g2(2) .ne. 2 ) call abort () + +end + +! { dg-final { scan-tree-dump-times " static integer\\\(kind=4\\\) a = 0;" 2 "original" } } +! { dg-final { scan-tree-dump-times " b = 0;" 2 "original" } } +! { dg-final { cleanup-tree-dump "original" } }