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.
/* 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))
--- /dev/null
+! { 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