PR fortran/98411 - Pointless warning for static variables

Variables with explicit SAVE attribute cannot end up on the stack.
There is no point in checking whether they should be moved off the
stack to static storage.

gcc/fortran/ChangeLog:

	PR fortran/98411
	* trans-decl.c (gfc_finish_var_decl): Add check for explicit SAVE
	attribute.

gcc/testsuite/ChangeLog:

	PR fortran/98411
	* gfortran.dg/pr98411.f90: New test.
This commit is contained in:
Harald Anlauf 2021-05-17 21:35:38 +02:00
parent 346cbaf578
commit 09867aa0ef
2 changed files with 17 additions and 0 deletions

View File

@ -738,6 +738,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.save != SAVE_EXPLICIT
&& 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. */

View File

@ -0,0 +1,16 @@
! { dg-do compile }
! { dg-options "-Wall -fautomatic -fmax-stack-var-size=100" }
! PR fortran/98411 - Pointless warning for static variables
module try
implicit none
integer, save :: a(1000)
contains
subroutine initmodule
real, save :: b(1000)
logical :: c(1000) ! { dg-warning "moved from stack to static storage" }
a(1) = 42
b(2) = 3.14
c(3) = .true.
end subroutine initmodule
end module try