From patchwork Fri Sep 17 20:02:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 45146 X-Patchwork-Delegate: jwakely.gcc@gmail.com Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8C7B43857017 for ; Fri, 17 Sep 2021 20:03:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8C7B43857017 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1631908993; bh=ekUzUZpv2C8d6Tl98axx+TElbMrRII42bgKGsvf32Nk=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=U/qwRgiSDkzoEeq5odxV55tHhOGQxtkWJBCLFi/wPCR9UQ5G/dHGNSc1/ys/jSKmm hN9/9BjgxhvshFATU5aIFwTaMqkVS8gHH7TAXfOhF9nFaFg7j/mM1YeW907i5T7b2e I688R8vjEmZxLDZEdkxJjrZsN0y0ajQfuCxKy/Tc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) by sourceware.org (Postfix) with ESMTPS id 0102B385840D; Fri, 17 Sep 2021 20:02:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0102B385840D X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [79.232.159.45] ([79.232.159.45]) by web-mail.gmx.net (3c-app-gmx-bs54.server.lan [172.19.170.138]) (via HTTP); Fri, 17 Sep 2021 22:02:23 +0200 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH, committed] PR fortran/102366] [10/11/12 Regression] large arrays no longer become static Date: Fri, 17 Sep 2021 22:02:23 +0200 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:XwqwcFvpiXwSdZuHzSLImsl958a/ei4NcsgUO32Aj1tiDZkvfjV4iqykQSj9HdlpMzXeB rfCYT4kBe2w1TphtUJ1I72X+CPG3VDmel8sCzpwvxBMttvXkZHgZMGQSViPPYlBt8B70POIZeAVN utsQDfTuCn8AoG568e8Y466Kq7l0t5JJUSa1kZCyWFq5aW19S736EtIgNQ5H5R4+lioYn3KANFc9 LrRlGqjmiz3F5m/nseXhTR3IxBuVfWnExKdH8Dg23ti+fKNj1SVb9fwQo3HkYBjoV/CbM2jgMquT mU= X-UI-Out-Filterresults: notjunk:1;V03:K0:QfQ6zD9G7Hs=:jv7FqeZ3ZV1R2Kq46hs1zm gbta7dry7WYyKymPoAf/FEnCPNCw2X/fYWEoCR7twp8dCVrWZ+1aSQutHojePURI+XV+U0pog cLyeffMHjeEtfzLkhgDRn2/s7vAEa1rrjdVhtzfrRCnvnBl60iNL3+tgub4JSe9itHv17yyw2 pLC7I2/1NGh0N5eeI/UkQzpYDWwYZ1nkzkMl/pY3q0TTJeRZnGoHLyAJYvFjlTNi5P+0A4cL7 KqVPsHGszrauNAm8DAvhdxcJa0DRchVehWJmfLNYdDJUkKu1cjekG6hplsAaRR7y16jYD5Ez6 3eTtQdp1zSrnVFCIVAVYNhaQfJh+hyhdWj08NWgMqm9HEMSciuDRfG+jkEyJUvFaAiHqBjOKw IDfFWPhOW9EDiojk4kEu7MKQ4JuQDV4ClM7iA9O/eBTIu6R3pGJy3WP7pioR3nsWspi4mBaQk 1bfPAWTRcZnpchZDEDONVdx6hxpZlbEfjRmJLTfaKhO0pg7HB1Wzmim01X4KE4bSfKNYf8R/g xQcogVBBadjpAJGCTwbxrJjE3IRIC/OAGtVe5oLee3piGtvudu4+wZ82LqrAc4AcSnRZ1zq1V DRFYueqScMXgVQzmsONeaPMztPDSugydPPsdVY9kyL4Nq2vRtSb71T8fjaqro0I1wLRFoEH5J T4N6mbgr9lVzq31W67NV494q8nesjcN9njMrs7j6gRnP2Ac35TmOFp1NnstZpWkfq//btd8Pl SHcpzYLYFWRms8A7bJVecC9IQg35CfTEfpVdSpTOMDmn9xoWKdFJPO76kjXOtvJmdBdtV5Pdl iAMTEYn X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Harald Anlauf via Gcc-patches From: Harald Anlauf Reply-To: Harald Anlauf Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The attempt to fix a misleading warning lead to a regression that prevented putting large variables in the main into static storage. So instead of preventing the move, we now disable the useless warning for variables in the main. Regtested on x86_64-pc-linux-gnu. The patch was ok'ed in the PR by Jakub. Pushed to mainline; will backport to affected branches. Note, however, that the Fortran 2018 standard has: F2018 8.5.16 SAVE attribute (4) A variable, common block, or procedure pointer declared in the scoping unit of a main program, [...] implicitly has the SAVE attribute We already have code that sets IMPLICIT_SAVE for variables e.g. in (sub)modules, but for code such as real(kind=4) :: a(10) a=1.0 end (with and without PROGRAM statement) the array turns out to be too small to currently get moved to static storage. I get in decl.c::match_attr_spec: gfc_state_stack->state == COMP_NONE, which defeated my attempts to an ultimate solution. I have opened https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102390 to track this. Thanks, Harald commit 51166eb2c534692c3c7779def24f83c8c3811b98 Author: Harald Anlauf Date: Fri Sep 17 21:45:33 2021 +0200 Fortran - (large) arrays in the main shall be static gcc/fortran/ChangeLog: PR fortran/102366 * trans-decl.c (gfc_finish_var_decl): Disable the warning message for variables moved from stack to static storange if they are declared in the main, but allow the move to happen. gcc/testsuite/ChangeLog: PR fortran/102366 * gfortran.dg/pr102366.f90: New test. diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index bed61e2325d..3bd8a0fe935 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -743,7 +743,6 @@ 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 @@ -757,7 +756,9 @@ gfc_finish_var_decl (tree decl, gfc_symbol * sym) || sym->attr.allocatable) && !DECL_ARTIFICIAL (decl)) { - if (flag_max_stack_var_size > 0) + if (flag_max_stack_var_size > 0 + && !(sym->ns->proc_name + && sym->ns->proc_name->attr.is_main_program)) gfc_warning (OPT_Wsurprising, "Array %qs at %L is larger than limit set by " "%<-fmax-stack-var-size=%>, moved from stack to static " diff --git a/gcc/testsuite/gfortran.dg/pr102366.f90 b/gcc/testsuite/gfortran.dg/pr102366.f90 new file mode 100644 index 00000000000..d002f64a8ae --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr102366.f90 @@ -0,0 +1,9 @@ +! { dg-do compile } +! { dg-options "-fdump-tree-original -Wall" } +! { dg-final { scan-tree-dump-times "static real" 1 "original" } } +! PR fortran/102366 - large arrays no longer become static + +program p + real(kind=4) :: a(16776325) + a=1.0 +end