From patchwork Wed Jan 2 10:38:32 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 208987 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 111972C0095 for ; Wed, 2 Jan 2013 21:38:44 +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=1357727926; 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=N3ECAqq4tA+dCChMsWvS X5rZGGg=; b=G+jL/DvkImi0sJdu8ITi/DRAhJX6SCjytazAmXB5dUTy8BH3qdys WQcXTXHob9SIYtImg6l1IOpWwMdX2yVgoXYUpIFqoFMJPzWricOoDSM5VHjsWoc2 pPdVbLDE3XN1O76lIyM0ju0a+RmRJzznxdyux0jzwRZsZUdXDSF+KNg= 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=inbqPDiepG1aTbjyXkYhaSZTrJhqV28keDVoDiEW0qKv5WjdEQ/5q13FuvWin+ xR4OCW3AUzo1tlBa8FtqtqWVVacZ4Oyku1OE1S0SsGdn+DFPPo8Ej8VB2J8DEtQo HT0dnvzc/CXX1U/GYGyAdMUFIFOy06fRr6oIFPw4LWe5k=; Received: (qmail 26998 invoked by alias); 2 Jan 2013 10:38:39 -0000 Received: (qmail 26904 invoked by uid 22791); 2 Jan 2013 10:38:38 -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 10:38:33 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id D1D752E46A; Wed, 2 Jan 2013 05:38:32 -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 G6oIP57eOhmv; Wed, 2 Jan 2013 05:38:32 -0500 (EST) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id A89952E219; Wed, 2 Jan 2013 05:38:32 -0500 (EST) Received: by kwai.gnat.com (Postfix, from userid 4192) id A41C43FF09; Wed, 2 Jan 2013 05:38:32 -0500 (EST) Date: Wed, 2 Jan 2013 05:38:32 -0500 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Hristian Kirtchev Subject: [Ada] Illegal forward reference in pragma Postcondition Message-ID: <20130102103832.GA19985@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 ensures that the boolean expression of pragma Postcondition is preanalyzed at the point of declaration when the pragma appears inside a subprogram body. ------------ -- Source -- ------------ -- main.adb procedure Main is pragma Postcondition (X'Old = 1); X : Integer := 0; begin X := 2; end Main; ----------------- -- Compilation -- ----------------- $ gcc -c -gnata main.adb main.adb:2:26: "X" is undefined Tested on x86_64-pc-linux-gnu, committed on trunk 2013-01-02 Hristian Kirtchev * sem_attr.adb (Analyze_Attribute): Skip the special _Parent scope generated for subprogram inlining purposes while trying to locate the enclosing function. * sem_prag.adb (Analyze_Pragma): Preanalyze the boolean expression of pragma Postcondition when the pragma comes from source and appears inside a subprogram body. Index: sem_prag.adb =================================================================== --- sem_prag.adb (revision 194788) +++ sem_prag.adb (working copy) @@ -12748,7 +12748,6 @@ when Pragma_Postcondition => Postcondition : declare In_Body : Boolean; - pragma Warnings (Off, In_Body); begin GNAT_Pragma; @@ -12756,10 +12755,22 @@ Check_At_Most_N_Arguments (2); Check_Optional_Identifier (Arg1, Name_Check); - -- All we need to do here is call the common check procedure, - -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7. + -- Verify the proper placement of the pragma. The remainder of the + -- processing is found in Sem_Ch6/Sem_Ch7. Check_Precondition_Postcondition (In_Body); + + -- When the pragma is a source contruct and appears inside a body, + -- preanalyze the boolean_expression to detect illegal forward + -- references: + + -- procedure P is + -- pragma Postcondition (X'Old ...); + -- X : ... + + if Comes_From_Source (N) and then In_Body then + Preanalyze_Spec_Expression (Expression (Arg1), Any_Boolean); + end if; end Postcondition; ------------------ Index: sem_attr.adb =================================================================== --- sem_attr.adb (revision 194786) +++ sem_attr.adb (working copy) @@ -4586,11 +4586,26 @@ -- During pre-analysis, Prag is the enclosing pragma node if any begin - -- Find enclosing scopes, excluding loops + -- Find the proper enclosing scope CS := Current_Scope; - while Ekind (CS) = E_Loop loop - CS := Scope (CS); + while Present (CS) loop + + -- Skip generated loops + + if Ekind (CS) = E_Loop then + CS := Scope (CS); + + -- Skip the special _Parent scope generated to capture references + -- to formals during the process of subprogram inlining. + + elsif Ekind (CS) = E_Function + and then Chars (CS) = Name_uParent + then + CS := Scope (CS); + else + exit; + end if; end loop; PS := Scope (CS);