]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR fortran/91413 Generate warning when making array static
authorjb <jb@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 11 Aug 2019 09:42:41 +0000 (09:42 +0000)
committerjb <jb@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 11 Aug 2019 09:42:41 +0000 (09:42 +0000)
When moving a local variable from the stack to static storage, the
procedure is no longer safe to be called recursively or concurrently
from multiple threads.  Thus generate a warning when this is done.
Also double the default limit for switching from stack to static.

Regtested on x86_64-pc-linux-gnu.

gcc/fortran/ChangeLog:

2019-08-11  Janne Blomqvist  <jb@gcc.gnu.org>

PR fortran/91413
* invoke.texi (-fmax-stack-var-size): Document increased default.
* options.c (gfc_post_options): Increase default stack var size to
65536 bytes.
* trans-decl.c (gfc_finish_var_decl): Generate warning when local
array moved to static storage.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@274264 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/fortran/ChangeLog
gcc/fortran/invoke.texi
gcc/fortran/options.c
gcc/fortran/trans-decl.c

index 51dc89328c26cb360d5c74f2948ac913187b2646..d554991440bc3212ab0902399eeeb5724e025f4f 100644 (file)
@@ -1,3 +1,12 @@
+2019-08-11  Janne Blomqvist  <jb@gcc.gnu.org>
+
+       PR fortran/91413
+       * invoke.texi (-fmax-stack-var-size): Document increased default.
+       * options.c (gfc_post_options): Increase default stack var size to
+       65536 bytes.
+       * trans-decl.c (gfc_finish_var_decl): Generate warning when local
+       array moved to static storage.
+
 2019-08-10  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        * decl.c (match_old_style_init): Use a clearer error message.
index 3c1b2ac7a269c550602ddb7c902e2ef94feff863..1039c6084c4241de6ba3d526ce8e170fe7a1c9b9 100644 (file)
@@ -1720,7 +1720,7 @@ This option currently only affects local arrays declared with constant
 bounds, and may not apply to all character variables.
 Future versions of GNU Fortran may improve this behavior.
 
-The default value for @var{n} is 32768.
+The default value for @var{n} is 65536.
 
 @item -fstack-arrays
 @opindex @code{fstack-arrays}
index ef37cccec977998e112e7af4d06fc9c0d0a9bd32..146be2f1420a723e91ac18942df1d740573b8b24 100644 (file)
@@ -437,7 +437,7 @@ gfc_post_options (const char **pfilename)
 
   /* Set default.  */
   if (flag_max_stack_var_size == -2)
-    flag_max_stack_var_size = 32768;
+    flag_max_stack_var_size = 65536;
 
   /* Implement -fno-automatic as -fmax-stack-var-size=0.  */
   if (!flag_automatic)
index 86c3d3a97964485f9a06a2ed65f0df3448bcbb23..2a9b852568a8c5ed0cb4b2d7d48b986be3d6f3f5 100644 (file)
@@ -753,6 +753,16 @@ gfc_finish_var_decl (tree decl, gfc_symbol * sym)
          || sym->attr.allocatable)
       && !DECL_ARTIFICIAL (decl))
     {
+      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.",
+                  sym->name, &sym->declared_at);
+
       TREE_STATIC (decl) = 1;
 
       /* Because the size of this variable isn't known until now, we may have