https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98411
--- Comment #9 from anlauf at gcc dot gnu.org ---
(In reply to anlauf from comment #8)
Looking some more into this: I couldn't find a consistent concept of setting
variables to implicit-save as e.g. described in F2018 section 8.5.16 clause 4.
A hackish approach to fix the remaining part of this PR could look like
diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c
index 406b4aeb1d4..a2498a04fb9 100644
--- a/gcc/fortran/trans-decl.c
+++ b/gcc/fortran/trans-decl.c
@@ -737,8 +737,10 @@ 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->ns->proc_name && sym->ns->proc_name->attr.is_main_program)
&& !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. */
However, the first part of this patch would only address variables in the main
program, and the second part needs proper setting of SAVE_IMPLICIT, which is
not yet done.
As a sidenote: the above would regtest ok and fix comment#0.