From patchwork Sat Aug 10 20:34:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janne Blomqvist X-Patchwork-Id: 1145189 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-506636-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="SoHebmA5"; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="nSsXDZmM"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 465YkM5scQz9sP9 for ; Sun, 11 Aug 2019 06:34:33 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; q=dns; s=default; b=XhjNsUeqIBSP vn1KNe+3L2MxsqeAFVAjwAzd9NI7WEMTe/785/XkMOlLHUW/DDF8+vDO7fOZqiT0 xbhO+GS4KKj8CxJ9r6UB302m2zY00d3pm8MhQPuB3jzk6oSJZFg3k8RHZZGaKG51 oinAhd9zJqpWqN21aKpfyr+P1oXrZxg= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; s=default; bh=/uP1o1+NWz1ouP6/Tn K0I85chJc=; b=SoHebmA5cBWKsQCBbul7zPtbVYbcrSDHCX/EDKgjhhxgTHB1tL v+iZ1fm1ji5nWFVx+pJDB4yJQq9bBpUkhX86JH7ior9eCgxmkDcuonZT8RsSugZZ k6CMctHCCCrwX6Tk1Jf8qxgxY+Zr/jiJ21NH7DBDcTIKEnYEyk9iz4txQ= Received: (qmail 86933 invoked by alias); 10 Aug 2019 20:34:26 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 86914 invoked by uid 89); 10 Aug 2019 20:34:26 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.8 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=blomqvist, Janne, jb@gcc.gnu.org, @item X-HELO: mail-lj1-f193.google.com Received: from mail-lj1-f193.google.com (HELO mail-lj1-f193.google.com) (209.85.208.193) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 10 Aug 2019 20:34:24 +0000 Received: by mail-lj1-f193.google.com with SMTP id z17so6659851ljz.0; Sat, 10 Aug 2019 13:34:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=aLdZwo6fAeFqbPSSbdEPhJIIG4zkbh3zDNEukRvSkWg=; b=nSsXDZmM8G7g9eIqeAbJXVy1H5bti/TSjp/AgEJJJ4Ritkj7tOtylMvCLB1TPFGK4S p5JaqsKYNgbEE4S5LWbduy81P9RvHHOZpK2o00wTRx6deqdxK/r0G2zsiOqUqyhtcG+C SXtFzcRho6bET7tTuysMX5kt16XhW7cWtIdS8UloLCpiWAh9Cyh6nHnvrBtDvz0dhdBB fCg+GKiiM0HgufBGAtVPVs9z04rZlzUgwHn/iDeeb+9WSxq0FOdWsN5opszotP6UY4wC 4XTpY+2/XgdPJ7j3dpmiNP3kKih/VgWUwuXKVgN5xzOfJy6N1+OF3gQ+mCNBwnDkhF3Z Exhw== Received: from ws.lan (88-114-247-254.elisa-laajakaista.fi. [88.114.247.254]) by smtp.gmail.com with ESMTPSA id w13sm1054927lfe.8.2019.08.10.13.34.20 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 10 Aug 2019 13:34:20 -0700 (PDT) From: Janne Blomqvist To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Cc: Janne Blomqvist Subject: [PATCH,fortran] PR 91413 Generate warning when making array static Date: Sat, 10 Aug 2019 23:34:15 +0300 Message-Id: <20190810203415.9460-1-blomqvist.janne@gmail.com> 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, Ok for trunk? gcc/fortran/ChangeLog: 2019-08-10 Janne Blomqvist 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. --- gcc/fortran/invoke.texi | 2 +- gcc/fortran/options.c | 2 +- gcc/fortran/trans-decl.c | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/gcc/fortran/invoke.texi b/gcc/fortran/invoke.texi index 3c1b2ac7a26..1039c6084c4 100644 --- a/gcc/fortran/invoke.texi +++ b/gcc/fortran/invoke.texi @@ -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} diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c index ef37cccec97..146be2f1420 100644 --- a/gcc/fortran/options.c +++ b/gcc/fortran/options.c @@ -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) diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index 86c3d3a9796..2a9b852568a 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -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