From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6100 invoked by alias); 30 Jun 2016 18:07:06 -0000 Mailing-List: contact fortran-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: fortran-owner@gcc.gnu.org Received: (qmail 6079 invoked by uid 89); 30 Jun 2016 18:07:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.2 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=acts, HTo:U*burnus, HTo:U*jvdelisle X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 30 Jun 2016 18:07:04 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AF3FC80B20; Thu, 30 Jun 2016 18:07:02 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-51.ams2.redhat.com [10.36.116.51]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u5UI70OZ021502 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 30 Jun 2016 14:07:01 -0400 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id u5UI6v6h027595; Thu, 30 Jun 2016 20:06:57 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id u5UI6s6n027594; Thu, 30 Jun 2016 20:06:54 +0200 Date: Thu, 30 Jun 2016 18:07:00 -0000 From: Jakub Jelinek To: fortran@gcc.gnu.org, Paul Richard Thomas , Jerry DeLisle , Tobias Burnus Cc: gcc-patches@gcc.gnu.org Subject: [RFC] Change order of Fortran BLOCK_VARS (PR fortran/71687) Message-ID: <20160630180654.GR7387@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-SW-Source: 2016-06/txt/msg00128.txt.bz2 Hi! While usually the order of vars in block scope isn't that significant, e.g. on the following testcase with -fopenmp -fstack-arrays it does matter if we have local declaration of a temporary and then local declaration of a VLA that uses that other temporary as the TYPE_SIZE_UNIT, or the other way around (we ICE if we first see the VLA and firstprivatize the variable, only to later on discover it is a local var). pushdecl is called on them in the right order (scalar temporary first, then VLA that uses it), but the names chain is LIFO. Actually, with gfc_merge_block_scope it seems we end up in quite randomish order. So, is it intentional that pushdecl / getdecls acts like a LIFO? Though, it seems user vars are pushdecled in the reverse order of declarations, but gfc_add_decl_to_function is called in the user declared order, so perhaps for the following patch we'd also need to decl = nreverse (saved_function_decls); in gfc_generate_function_code and similarly in gfc_process_block_locals decl = nreverse (saved_local_decls); What do you think about this? Note, nreverse is fairly cheap, it is linear in the chain length. 2016-06-30 Jakub Jelinek PR fortran/71687 * f95-lang.c (struct binding_level): Add reversed field. (clear_binding_level): Adjust initializer. (getdecls): If reversed is clear, set it and nreverse the names chain before returning it. (poplevel): Use getdecls. * gfortran.dg/gomp/pr71687.f90: New test. --- gcc/fortran/f95-lang.c.jj 2016-06-29 10:46:33.000000000 +0200 +++ gcc/fortran/f95-lang.c 2016-06-30 17:11:44.350240191 +0200 @@ -286,6 +286,9 @@ binding_level { tree blocks; /* The binding level containing this one (the enclosing binding level). */ struct binding_level *level_chain; + /* True if nreverse has been already called on names; if false, names + are ordered from newest declaration to oldest one. */ + bool reversed; }; /* The binding level currently in effect. */ @@ -296,7 +299,7 @@ static GTY(()) struct binding_level *cur static GTY(()) struct binding_level *global_binding_level; /* Binding level structures are initialized by copying this one. */ -static struct binding_level clear_binding_level = { NULL, NULL, NULL }; +static struct binding_level clear_binding_level = { NULL, NULL, NULL, false }; /* Return true if we are in the global binding level. */ @@ -310,6 +313,11 @@ global_bindings_p (void) tree getdecls (void) { + if (!current_binding_level->reversed) + { + current_binding_level->reversed = true; + current_binding_level->names = nreverse (current_binding_level->names); + } return current_binding_level->names; } @@ -347,7 +355,7 @@ poplevel (int keep, int functionbody) binding level that we are about to exit and which is returned by this routine. */ tree block_node = NULL_TREE; - tree decl_chain = current_binding_level->names; + tree decl_chain = getdecls (); tree subblock_chain = current_binding_level->blocks; tree subblock_node; --- gcc/testsuite/gfortran.dg/gomp/pr71687.f90.jj 2016-06-30 17:12:27.279702475 +0200 +++ gcc/testsuite/gfortran.dg/gomp/pr71687.f90 2016-06-30 17:12:53.480374296 +0200 @@ -0,0 +1,11 @@ +! PR fortran/71687 +! { dg-do compile } +! { dg-additional-options "-fstack-arrays -O2" } + +subroutine s (n, x) + integer :: n + real :: x(n) +!$omp parallel + x(1:n) = x(n:1:-1) +!$omp end parallel +end Jakub