From patchwork Wed Jan 2 09:39:44 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 208981 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 3FAA92C0094 for ; Wed, 2 Jan 2013 20:39:58 +1100 (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=1357724398; 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=2AbeRX0zxApjRt724AW5 +rSAoDY=; b=BEr6EteykMk05NE5IOSubP9JRHPwkvuNxNzgJ7AQ9gr6PsMBvAD8 srUBrobcBhXzEo/OWgJIZyYtU1j/U7g4U+cCJlrR6AT6+E53rhWEiYmiMxFaomHp 5cLQfntukh8DaGkzQ0fXTDrCfYLArPHqYO4lyacnR06ozKmnPe425TU= 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=LAVHXsz6dQ4TpmHZEKP+Mk6/ATYBkJALcf7zD4rAMR+Y94NFqKB6xccySj+dCy HytgeJjShCAlvIiIzcYnwJJI6A+24hj88sY9g/GSpHeVAjbnJsBOhkFw580GflIS Y2FhUoWP2DLZGK9EQvYzyCe9EpuOOOkCPHOE6x0Uz4CO8=; Received: (qmail 28603 invoked by alias); 2 Jan 2013 09:39:52 -0000 Received: (qmail 28584 invoked by uid 22791); 2 Jan 2013 09:39:51 -0000 X-SWARE-Spam-Status: No, hits=-0.4 required=5.0 tests=AWL, BAYES_50, KHOP_SPAMHAUS_DROP, 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; Wed, 02 Jan 2013 09:39:45 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 744532E21D; Wed, 2 Jan 2013 04:39:44 -0500 (EST) 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 mH0s7b2bOcA5; Wed, 2 Jan 2013 04:39:44 -0500 (EST) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id 1608C2E464; Wed, 2 Jan 2013 04:39:44 -0500 (EST) Received: by kwai.gnat.com (Postfix, from userid 4192) id 14BB33FF09; Wed, 2 Jan 2013 04:39:44 -0500 (EST) Date: Wed, 2 Jan 2013 04:39:44 -0500 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Thomas Quinot Subject: [Ada] Wrong evaluation order for AND THEN in Pre/Post on library subprogram Message-ID: <20130102093944.GA31935@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 change fixes the circuitry that processes Pre/Post aspects. Previously when an AND THEN expression was used in such an aspect on a library level subprogram, the operands would be evaluated in the wrong order. Test case: $ gnatmake -q call_p $ ./call_p F( 1) -> TRUE F( 2) -> TRUE P called F( 1) -> TRUE F( 2) -> FALSE Exception name: SYSTEM.ASSERTIONS.ASSERT_FAILURE Message: failed precondition from p.ads:2 -- gnat.adc pragma Ada_2012; pragma Check_Policy (Precondition, Check); -- sources with Ada.Exceptions; with Ada.Text_IO; use Ada.Text_IO; with Split_Pre_Order; with P; procedure Call_P is begin Split_Pre_Order.Pre_Array := (1 => True, 2 => True); P; Split_Pre_Order.Pre_Array (2) := False; begin P; exception when E : others => Put_Line (Ada.Exceptions.Exception_Information (E)); end; end Call_P; with Ada.Text_IO; use Ada.Text_IO; procedure P is begin Put_Line ("P called"); end P; with Split_Pre_Order; procedure P with Pre => Split_Pre_Order.F (1) and then Split_Pre_Order.F (2); pragma Ada_2012; with Ada.Exceptions; with Ada.Text_IO; use Ada.Text_IO; pragma Check_Policy (Precondition, Check); procedure Split_Pre_Order is Pre_Array : array (1 .. 2) of Boolean; function F (Index : Integer) return Boolean is Result : constant Boolean := Pre_Array (Index); begin Put_Line ("F(" & Index'Img & ") -> " & Result'Img); return Result; end F; procedure P with Pre => F (1) and then F (2); procedure P is begin Put_Line ("P called"); end P; begin Pre_Array := (1 => True, 2 => True); P; Pre_Array := (1 => True, 2 => False); begin P; exception when E : others=> Put_Line ("Exception raised: " & Ada.Exceptions.Exception_Information (E)); end; end Split_Pre_Order; with Ada.Text_IO; use Ada.Text_IO; package body Split_Pre_Order is function F (Index : Integer) return Boolean is Result : constant Boolean := Pre_Array (Index); begin Put_Line ("F(" & Index'Img & ") -> " & Result'Img); return Result; end F; end Split_Pre_Order; package Split_Pre_Order is Pre_Array : array (1 .. 2) of Boolean; function F (Index : Integer) return Boolean; end Split_Pre_Order; Tested on x86_64-pc-linux-gnu, committed on trunk 2013-01-02 Thomas Quinot * sem_ch13.adb (Analyze_Aspect_Specifications): For a Pre/Post aspect that applies to a library subprogram, prepend corresponding pragma to the Pragmas_After list, in order for split AND THEN sections to be processed in the expected order. Index: sem_ch13.adb =================================================================== --- sem_ch13.adb (revision 194782) +++ sem_ch13.adb (working copy) @@ -1602,11 +1602,22 @@ -- with delay of visibility for the expression analysis. -- If the entity is a library-level subprogram, the pre/ - -- postconditions must be treated as late pragmas. + -- postconditions must be treated as late pragmas. Note + -- that they must be prepended, not appended, to the list, + -- so that split AND THEN sections are processed in the + -- correct order. if Nkind (Parent (N)) = N_Compilation_Unit then - Add_Global_Declaration (Aitem); + declare + Aux : constant Node_Id := Aux_Decls_Node (Parent (N)); + begin + if No (Pragmas_After (Aux)) then + Set_Pragmas_After (Aux, New_List); + end if; + Prepend (Aitem, Pragmas_After (Aux)); + end; + -- If it is a subprogram body, add pragmas to list of -- declarations in body. @@ -1930,7 +1941,7 @@ else if No (Pragmas_After (Aux)) then - Set_Pragmas_After (Aux, Empty_List); + Set_Pragmas_After (Aux, New_List); end if; Append (Aitem, Pragmas_After (Aux));