From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22888 invoked by alias); 9 Apr 2011 09:02:46 -0000 Received: (qmail 22870 invoked by uid 22791); 9 Apr 2011 09:02:45 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (194.98.77.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 09 Apr 2011 09:02:40 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 74693CB01EA; Sat, 9 Apr 2011 11:02:39 +0200 (CEST) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rn+r1fYxQJDq; Sat, 9 Apr 2011 11:02:36 +0200 (CEST) Received: from [192.168.1.2] (bon31-9-83-155-120-49.fbx.proxad.net [83.155.120.49]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mel.act-europe.fr (Postfix) with ESMTP id 626E9CB0362; Sat, 9 Apr 2011 11:02:36 +0200 (CEST) From: Eric Botcazou To: "N.M. Maclaren" Subject: Re: Implement stack arrays even for unknown sizes Date: Sat, 09 Apr 2011 09:02:00 -0000 User-Agent: KMail/1.9.9 Cc: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org References: In-Reply-To: MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201104091056.57952.ebotcazou@adacore.com> Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-04/txt/msg00678.txt.bz2 > There is actually a much better approach, which was done in Algol 68 > and seems now to be done only in Ada. As far as the compiler > implementation goes, it is a trivial variation on what you have done, > but there is a little more work in the run-time system. Obviously this depends on the compiler. GNAT allocates all local arrays on the primary stack for example. > That is to use primary and secondary stacks. The primary is for the > linkage, scalars, array descriptors and very small, fixed-size arrays. > The secondary is for all other arrays with automatic scope. You get > all of the benefits that you mention, because both are true stacks, > and the scope of the secondary stack is controlled by that of the > primary. GNAT has a secondary stack, but it is only used to return objects whose size is self-referential, i.e. isn't given by the return type of the function. > You need a single secondary stack pointer (and preferably limit, for > checking), which can be global variables. If a procedure uses the > secondary stack, it needs to restore it on leaving, or when leaving > a scope including an allocation - but you have already implemented > that! Not exactly, managing a secondary stack isn't supported in the GENERIC IL, you need to do it explicitly by inserting calls to the runtime at relevant points. As a consequence, this isn't an efficient mechanism, hence the restricted use. -- Eric Botcazou