From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from troutmask.apl.washington.edu (troutmask.apl.washington.edu [128.95.76.21]) by sourceware.org (Postfix) with ESMTPS id 73DB03858430 for ; Thu, 31 Mar 2022 18:49:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 73DB03858430 Received: from troutmask.apl.washington.edu (localhost [127.0.0.1]) by troutmask.apl.washington.edu (8.16.1/8.16.1) with ESMTPS id 22VInshW057745 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Thu, 31 Mar 2022 11:49:54 -0700 (PDT) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.16.1/8.16.1/Submit) id 22VInrR5057744; Thu, 31 Mar 2022 11:49:53 -0700 (PDT) (envelope-from sgk) Date: Thu, 31 Mar 2022 11:49:53 -0700 From: Steve Kargl To: Thomas Koenig Cc: "fortran@gcc.gnu.org" Subject: Re: allocatable arrays and -fmax-stack-var-size Message-ID: <20220331184953.GA57710@troutmask.apl.washington.edu> References: <20220331170747.GA57166@troutmask.apl.washington.edu> <4f4c6b5f-995f-385a-bacc-59e96090dc97@netcologne.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4f4c6b5f-995f-385a-bacc-59e96090dc97@netcologne.de> X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: fortran@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Fortran mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Mar 2022 18:49:57 -0000 On Thu, Mar 31, 2022 at 08:36:37PM +0200, Thomas Koenig wrote: > Hi Steve, > > > So, it seems that at some point in the past, the option > > -fmax-stack-var-size was expanded to allow the placement > > of an allocatable array into static memory. This has > > a possibly unintended consequence in that automatic > > deallocation of an allocatable array does not (or can > > not) occur. > > Sounds like a bug to me, and if your test program worked > in a previous release, it's a regression. > > Probably best to open a PR. > Thomas Seems someone from Fortran Discourse forum beat me to it. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105117 With all of the work on openmp, I wasn't sure if this was intended or not. Either way it is surprising to me that an allocatable array is placed in static memory. I went looking and found this chunk of code in trans-decl.cc (lines 743-774 where I removed the paragraph warning). /* Keep variables larger than max-stack-var-size off stack. */ if (!(sym->ns->proc_name && sym->ns->proc_name->attr.recursive) && !sym->attr.automatic && sym->attr.save != SAVE_EXPLICIT && sym->attr.save != SAVE_IMPLICIT && INTEGER_CST_P (DECL_SIZE_UNIT (decl)) && !gfc_can_put_var_on_stack (DECL_SIZE_UNIT (decl)) /* Put variable length auto array pointers always into stack. */ && (TREE_CODE (TREE_TYPE (decl)) != POINTER_TYPE || sym->attr.dimension == 0 || sym->as->type != AS_EXPLICIT || sym->attr.pointer || sym->attr.allocatable) && !DECL_ARTIFICIAL (decl)) { if (flag_max_stack_var_size > 0 && !(sym->ns->proc_name && sym->ns->proc_name->attr.is_main_program)) gfc_warning (OPT_Wsurprising, ... sym->name, &sym->declared_at); TREE_STATIC (decl) = 1; If I set the last line to 0, I get what I expect as far as an allocatable array. I have been unable to decipher the 12 line conditional. -- Steve