public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Harald Anlauf <anlauf@gmx.de>
To: fortran <fortran@gcc.gnu.org>, gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH] Fortran: ASSOCIATE variables should not be TREE_STATIC [PR95107]
Date: Mon, 6 Feb 2023 21:10:38 +0100	[thread overview]
Message-ID: <trinity-9557dbd4-3896-48bc-8096-d72310da093c-1675714238918@3c-app-gmx-bap04> (raw)

[-- Attachment #1: Type: text/plain, Size: 252 bytes --]

Dear all,

as the PR shows, it is likely not a good idea to try to make an
ASSOCIATE variable static when -fno-automatic is specified, so
rather keep it on the stack.

Attached patch regtested on x86_64-pc-linux-gnu.  OK for mainline?

Thanks,
Harald


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr95107.diff --]
[-- Type: text/x-patch, Size: 1862 bytes --]

From c29eb3dbe8c541ef83d5fdf12cafa015ed9447ee Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Mon, 6 Feb 2023 20:59:51 +0100
Subject: [PATCH] Fortran: ASSOCIATE variables should not be TREE_STATIC
 [PR95107]

gcc/fortran/ChangeLog:

	PR fortran/95107
	* trans-decl.cc (gfc_finish_var_decl): With -fno-automatic, do not
	make ASSOCIATE variables TREE_STATIC.

gcc/testsuite/ChangeLog:

	PR fortran/95107
	* gfortran.dg/save_7.f90: New test.
---
 gcc/fortran/trans-decl.cc            |  1 +
 gcc/testsuite/gfortran.dg/save_7.f90 | 17 +++++++++++++++++
 2 files changed, 18 insertions(+)
 create mode 100644 gcc/testsuite/gfortran.dg/save_7.f90

diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index 7a077801919..f7a7ff607cd 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -742,6 +742,7 @@ gfc_finish_var_decl (tree decl, gfc_symbol * sym)
   /* 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.associate_var
       && sym->attr.save != SAVE_EXPLICIT
       && sym->attr.save != SAVE_IMPLICIT
       && INTEGER_CST_P (DECL_SIZE_UNIT (decl))
diff --git a/gcc/testsuite/gfortran.dg/save_7.f90 b/gcc/testsuite/gfortran.dg/save_7.f90
new file mode 100644
index 00000000000..dfbef12bec0
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/save_7.f90
@@ -0,0 +1,17 @@
+! { dg-do compile }
+! { dg-options "-O2 -fno-automatic" }
+!
+! PR fortran/95107 - do not make associate variables TREE_STATIC
+! Contributed by G.Steinmetz
+
+program p
+  type t
+     real, pointer :: a => null()
+  end type
+  type t2
+     type(t) :: b(1)
+  end type
+  type(t2), save :: x
+  associate (y => x%b)
+  end associate
+end
--
2.35.3


             reply	other threads:[~2023-02-06 20:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-06 20:10 Harald Anlauf [this message]
2023-02-07  2:13 ` Jerry D

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=trinity-9557dbd4-3896-48bc-8096-d72310da093c-1675714238918@3c-app-gmx-bap04 \
    --to=anlauf@gmx.de \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    /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).