Fortran: ASSOCIATE variables should not be TREE_STATIC [PR95107]
authorHarald Anlauf <anlauf@gmx.de>
Mon, 6 Feb 2023 19:59:51 +0000 (20:59 +0100)
committerHarald Anlauf <anlauf@gmx.de>
Tue, 7 Feb 2023 18:07:05 +0000 (19:07 +0100)
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
gcc/testsuite/gfortran.dg/save_7.f90 [new file with mode: 0644]

index 7a07780..f7a7ff6 100644 (file)
@@ -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 (file)
index 0000000..dfbef12
--- /dev/null
@@ -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