From patchwork Mon Apr 2 09:21:08 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 150095 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 96D3BB6EF3 for ; Mon, 2 Apr 2012 19:21:29 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1333963290; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Cc:Subject:Message-ID: MIME-Version:Content-Type:Content-Disposition:User-Agent: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=pJgfuUmI2uV9ar9f0DJx 4fHHeF8=; b=lrpQtjLXiXCVfYYmTFM8GChCFFno2odaGk5/RA7HHAoZk+8BsWUX TTrT1p/e6aBlkcCOeC3Xq0/EycinQoaaaU8lXO9IrCSjATco6gX98GcbEc8We5RD HojFLZhPR/b3XITYw8xY89+DK9D2rs5TGZw/RQSZ2FxyXk/TkMZsCo4= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type:Content-Disposition:User-Agent:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=Xa9yqRXIEHH2uE8akdT/P1zaf9H418di9AF0r8qe6ioLBbo9/mw5m95J3bd/eB p/QMbbys76pFcoNd8OMlnElArVG3lv/e0++ZMRAa1uYvedVj/LI9ieHO/0S/qIjb T6oF+Ad530L4tcVyGAVfFTjNt5kMcZZIMKMHQDmLcFTA0=; Received: (qmail 9414 invoked by alias); 2 Apr 2012 09:21:23 -0000 Received: (qmail 9406 invoked by uid 22791); 2 Apr 2012 09:21:22 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_HOSTKARMA_NO X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 02 Apr 2012 09:21:09 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 0B0D41C6510; Mon, 2 Apr 2012 05:21:09 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id eHGvFQih4no0; Mon, 2 Apr 2012 05:21:08 -0400 (EDT) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id DD8001C645B; Mon, 2 Apr 2012 05:21:08 -0400 (EDT) Received: by kwai.gnat.com (Postfix, from userid 4192) id DD0A73FEE8; Mon, 2 Apr 2012 05:21:08 -0400 (EDT) Date: Mon, 2 Apr 2012 05:21:08 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Hristian Kirtchev Subject: [Ada] Interaction between packed arrays and post conditions Message-ID: <20120402092108.GA16720@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) 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 This patch corrects the insertion of the compiler-generated routine which encapsulates the behavior of post conditions. When a formal parameter is of a packed array type, the compiler creates several helper subtypes and inserts them at the top of the related subprogram declaration list. Since the post conditions may reference formal parameters, the compiler-generated routine _postconditions must be inserted after the last internal declaration at the subprogram level. Tested on x86_64-pc-linux-gnu, committed on trunk 2012-04-02 Hristian Kirtchev * sem_ch6.adb (Last_Implicit_Declaration): New routine. (Process_PPCs): Insert the body of _postconditions after the last internally generated declaration. This ensures that actual subtypes created for formal parameters are visible and properly frozen as _postconditions may reference them. Index: sem_ch6.adb =================================================================== --- sem_ch6.adb (revision 186067) +++ sem_ch6.adb (working copy) @@ -11057,6 +11057,9 @@ -- that an invariant check is required (for an IN OUT parameter, or -- the returned value of a function. + function Last_Implicit_Declaration return Node_Id; + -- Return the last internally-generated declaration of N + ------------- -- Grab_CC -- ------------- @@ -11307,6 +11310,50 @@ end if; end Is_Public_Subprogram_For; + ------------------------------- + -- Last_Implicit_Declaration -- + ------------------------------- + + function Last_Implicit_Declaration return Node_Id is + Loc : constant Source_Ptr := Sloc (N); + Decls : List_Id := Declarations (N); + Decl : Node_Id; + Succ : Node_Id; + + begin + if No (Decls) then + Decls := New_List (Make_Null_Statement (Loc)); + Set_Declarations (N, Decls); + + elsif Is_Empty_List (Declarations (N)) then + Append_To (Decls, Make_Null_Statement (Loc)); + end if; + + -- Implicit and source declarations may be interspersed. Search for + -- the last implicit declaration which is either succeeded by a + -- source construct or is the last node in the declarative list. + + Decl := First (Declarations (N)); + while Present (Decl) loop + Succ := Next (Decl); + + -- The current declaration is the last one, do not return Empty + + if No (Succ) then + exit; + + -- The successor is a source construct + + elsif Comes_From_Source (Succ) then + exit; + end if; + + Next (Decl); + end loop; + + return Decl; + end Last_Implicit_Declaration; + -- Start of processing for Process_PPCs begin @@ -11712,7 +11759,7 @@ -- The entity for the _Postconditions procedure begin - Prepend_To (Declarations (N), + Insert_After (Last_Implicit_Declaration, Make_Subprogram_Body (Loc, Specification => Make_Procedure_Specification (Loc,