From patchwork Mon Aug 29 09:41:33 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 112003 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 2487CB6F92 for ; Mon, 29 Aug 2011 19:41:50 +1000 (EST) Received: (qmail 30082 invoked by alias); 29 Aug 2011 09:41:48 -0000 Received: (qmail 30064 invoked by uid 22791); 29 Aug 2011 09:41:47 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00 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, 29 Aug 2011 09:41:33 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 4D1F32BB114; Mon, 29 Aug 2011 05:41:33 -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 QU-DA+w9a-xb; Mon, 29 Aug 2011 05:41:33 -0400 (EDT) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id 390DF2BB10B; Mon, 29 Aug 2011 05:41:33 -0400 (EDT) Received: by kwai.gnat.com (Postfix, from userid 4192) id 37DA83FEE8; Mon, 29 Aug 2011 05:41:33 -0400 (EDT) Date: Mon, 29 Aug 2011 05:41:33 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Crash on use of 'Old Message-ID: <20110829094133.GA27785@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 The Ada2012 attribute 'Old is expanded into an object declaration that captures the value of a formal before execution. This patch fixes a bug that placed the object declaration in the wrong scope when the enclosing subprogram body had a single local declaration for a use clause. The following must compile quietly: gnatmake -q -gnat12 -gnata p1-tests.adb --- package P1 is package P2 is procedure Q (X : in out Integer); pragma Test_Case (Name => "Test case 1", Mode => Robustness, Ensures => X = X'Old); end P2; end P1; --- package P1.Tests is package P2_Tests is procedure Test_Q; end P2_Tests; end P1.Tests; --- with Ada.Text_IO; separate (P1.Tests) package body P2_Tests is procedure Wrap_Q_3 (X : in out Integer) is use P1.P2; begin Q (X); if X = X'Old then Ada.Text_IO.Put_Line ("postcondition violated"); end if; end Wrap_Q_3; procedure Test_Q is begin null; end Test_Q; end P2_Tests; --- package body P1.Tests is package body P2_Tests is separate; end P1.Tests; --- package body P1 is package body P2 is procedure Q (X : in out Integer) is begin null; end Q; end P2; end P1; --- Tested on x86_64-pc-linux-gnu, committed on trunk 2011-08-29 Ed Schonberg * exp_util.adb (Insert_Actions): Use clauses can be part of lists of declarations, and thus are likely insertion points for actions. Index: exp_util.adb =================================================================== --- exp_util.adb (revision 178162) +++ exp_util.adb (working copy) @@ -3028,6 +3028,11 @@ N_Task_Body_Stub | N_Task_Type_Declaration | + -- Use clauses can appear in lists of declarations + + N_Use_Package_Clause | + N_Use_Type_Clause | + -- Freeze entity behaves like a declaration or statement N_Freeze_Entity @@ -3328,8 +3333,6 @@ N_Unconstrained_Array_Definition | N_Unused_At_End | N_Unused_At_Start | - N_Use_Package_Clause | - N_Use_Type_Clause | N_Variant | N_Variant_Part | N_Validate_Unchecked_Conversion |