aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorHarald Anlauf <anlauf@gmx.de>2021-05-17 21:35:38 +0200
committerHarald Anlauf <anlauf@gmx.de>2021-05-17 21:35:38 +0200
commit09867aa0ef7568012650395189b735f9a34cf9b5 (patch)
treebd15fc740d3c48d17d7cdbaa7d497222858879c0 /gcc
parent346cbaf57828aef190de93271c0eb3f10c9aca61 (diff)
downloadgcc-09867aa0ef7568012650395189b735f9a34cf9b5.zip
gcc-09867aa0ef7568012650395189b735f9a34cf9b5.tar.gz
gcc-09867aa0ef7568012650395189b735f9a34cf9b5.tar.bz2
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/fortran/trans-decl.c1
-rw-r--r--gcc/testsuite/gfortran.dg/pr98411.f9016
2 files changed, 17 insertions, 0 deletions
diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c
index a170188..406b4ae 100644
--- a/gcc/fortran/trans-decl.c
+++ b/gcc/fortran/trans-decl.c
@@ -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. */
diff --git a/gcc/testsuite/gfortran.dg/pr98411.f90 b/gcc/testsuite/gfortran.dg/pr98411.f90
new file mode 100644
index 0000000..249afae
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr98411.f90
@@ -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