public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Steve Kargl <sgk@troutmask.apl.washington.edu>
To: Thomas Koenig <tkoenig@netcologne.de>
Cc: "fortran@gcc.gnu.org" <fortran@gcc.gnu.org>
Subject: Re: allocatable arrays and -fmax-stack-var-size
Date: Thu, 31 Mar 2022 11:49:53 -0700	[thread overview]
Message-ID: <20220331184953.GA57710@troutmask.apl.washington.edu> (raw)
In-Reply-To: <4f4c6b5f-995f-385a-bacc-59e96090dc97@netcologne.de>

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

      reply	other threads:[~2022-03-31 18:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-31 17:07 Steve Kargl
2022-03-31 18:36 ` Thomas Koenig
2022-03-31 18:49   ` Steve Kargl [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220331184953.GA57710@troutmask.apl.washington.edu \
    --to=sgk@troutmask.apl.washington.edu \
    --cc=fortran@gcc.gnu.org \
    --cc=tkoenig@netcologne.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).