public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Harald Anlauf <anlauf@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-5732] Fortran: ASSOCIATE variables should not be TREE_STATIC [PR95107]
Date: Tue,  7 Feb 2023 18:21:59 +0000 (GMT)	[thread overview]
Message-ID: <20230207182159.7AE503858D33@sourceware.org> (raw)

https://gcc.gnu.org/g:c36f3da534e7f411c5bc48c5b6b660e238167480

commit r13-5732-gc36f3da534e7f411c5bc48c5b6b660e238167480
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Mon Feb 6 20:59:51 2023 +0100

    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.

Diff:
---
 gcc/fortran/trans-decl.cc            |  1 +
 gcc/testsuite/gfortran.dg/save_7.f90 | 17 +++++++++++++++++
 2 files changed, 18 insertions(+)

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

                 reply	other threads:[~2023-02-07 18:21 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20230207182159.7AE503858D33@sourceware.org \
    --to=anlauf@gcc.gnu.org \
    --cc=gcc-cvs@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).