diff mbox series

[part2] PR fortran/98411 [10/11/12 Regression] Pointless: Array larger than ‘-fmax-stack-var-size=’, ...

Message ID trinity-26487c90-b6e0-491b-8f3a-ac49b600443f-1628111387370@3c-app-gmx-bap22
State New
Headers show
Series [part2] PR fortran/98411 [10/11/12 Regression] Pointless: Array larger than ‘-fmax-stack-var-size=’, ... | expand

Commit Message

Harald Anlauf Aug. 4, 2021, 9:09 p.m. UTC
Dear all,

here's the second part that should fix this regression for good.
The patch also adjusts the warning message to make it easier to
understand, using the suggestion by Tobias (see PR).

Since F2018 in principle makes RECURSIVE the default, which might
conflict with the purpose of the testcase, I chose to change the
options to include -std=f2008, and to verify that implicit SAVE
works the same as explicit SAVE.

Regtested on x86_64-pc-linux-gnu.  OK for affected branches?

Thanks,
Harald


Fortran: fix pointless warning for static variables

gcc/fortran/ChangeLog:

	PR fortran/98411
	* trans-decl.c (gfc_finish_var_decl): Adjust check to handle
	implicit SAVE as well as variables in the main program.  Improve
	warning message text.

gcc/testsuite/ChangeLog:

	PR fortran/98411
	* gfortran.dg/pr98411.f90: Adjust testcase options to restrict to
	F2008, and verify case of implicit SAVE.

Comments

Harald Anlauf Aug. 11, 2021, 7:28 p.m. UTC | #1
*Ping*

> Gesendet: Mittwoch, 04. August 2021 um 23:09 Uhr
> Von: "Harald Anlauf" <anlauf@gmx.de>
> An: "fortran" <fortran@gcc.gnu.org>, "gcc-patches" <gcc-patches@gcc.gnu.org>
> Betreff: [PATCH, part2] PR fortran/98411 [10/11/12 Regression] Pointless: Array larger than ‘-fmax-stack-var-size=’, ...
>
> Dear all,
> 
> here's the second part that should fix this regression for good.
> The patch also adjusts the warning message to make it easier to
> understand, using the suggestion by Tobias (see PR).
> 
> Since F2018 in principle makes RECURSIVE the default, which might
> conflict with the purpose of the testcase, I chose to change the
> options to include -std=f2008, and to verify that implicit SAVE
> works the same as explicit SAVE.
> 
> Regtested on x86_64-pc-linux-gnu.  OK for affected branches?
> 
> Thanks,
> Harald
> 
> 
> Fortran: fix pointless warning for static variables
> 
> gcc/fortran/ChangeLog:
> 
> 	PR fortran/98411
> 	* trans-decl.c (gfc_finish_var_decl): Adjust check to handle
> 	implicit SAVE as well as variables in the main program.  Improve
> 	warning message text.
> 
> gcc/testsuite/ChangeLog:
> 
> 	PR fortran/98411
> 	* gfortran.dg/pr98411.f90: Adjust testcase options to restrict to
> 	F2008, and verify case of implicit SAVE.
> 
>
diff mbox series

Patch

diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c
index 784f7b61ce1..bed61e2325d 100644
--- a/gcc/fortran/trans-decl.c
+++ b/gcc/fortran/trans-decl.c
@@ -743,8 +743,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.  */
@@ -757,13 +759,17 @@  gfc_finish_var_decl (tree decl, gfc_symbol * sym)
     {
       if (flag_max_stack_var_size > 0)
 	gfc_warning (OPT_Wsurprising,
-		     "Array %qs at %L is larger than limit set by"
-		     " %<-fmax-stack-var-size=%>, moved from stack to static"
-		     " storage. This makes the procedure unsafe when called"
-		     " recursively, or concurrently from multiple threads."
-		     " Consider using %<-frecursive%>, or increase the"
-		     " %<-fmax-stack-var-size=%> limit, or change the code to"
-		     " use an ALLOCATABLE array.",
+		     "Array %qs at %L is larger than limit set by "
+		     "%<-fmax-stack-var-size=%>, moved from stack to static "
+		     "storage. This makes the procedure unsafe when called "
+		     "recursively, or concurrently from multiple threads. "
+		     "Consider increasing the %<-fmax-stack-var-size=%> "
+		     "limit (or use %<-frecursive%>, which implies "
+		     "unlimited %<-fmax-stack-var-size%>) - or change the "
+		     "code to use an ALLOCATABLE array. If the variable is "
+		     "never accessed concurrently, this warning can be "
+		     "ignored, and the variable could also be declared with "
+		     "the SAVE attribute.",
 		     sym->name, &sym->declared_at);

       TREE_STATIC (decl) = 1;
diff --git a/gcc/testsuite/gfortran.dg/pr98411.f90 b/gcc/testsuite/gfortran.dg/pr98411.f90
index 249afaea419..7c906a96f60 100644
--- a/gcc/testsuite/gfortran.dg/pr98411.f90
+++ b/gcc/testsuite/gfortran.dg/pr98411.f90
@@ -1,5 +1,5 @@ 
 ! { dg-do compile }
-! { dg-options "-Wall -fautomatic -fmax-stack-var-size=100" }
+! { dg-options "-std=f2008 -Wall -fautomatic -fmax-stack-var-size=100" }
 ! PR fortran/98411 - Pointless warning for static variables

 module try
@@ -9,8 +9,10 @@  contains
   subroutine initmodule
     real, save :: b(1000)
     logical    :: c(1000) ! { dg-warning "moved from stack to static storage" }
+    integer    :: e(1000) = 1
     a(1) = 42
     b(2) = 3.14
     c(3) = .true.
+    e(5) = -1
   end subroutine initmodule
 end module try