From patchwork Mon Jun 14 10:10:37 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 55509 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 39BE6B7D81 for ; Mon, 14 Jun 2010 20:10:34 +1000 (EST) Received: (qmail 24123 invoked by alias); 14 Jun 2010 10:10:32 -0000 Received: (qmail 24114 invoked by uid 22791); 14 Jun 2010 10:10:31 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (212.99.106.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 14 Jun 2010 10:10:27 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id D69D9CB02BF; Mon, 14 Jun 2010 12:10:30 +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 TQfpZDby4doP; Mon, 14 Jun 2010 12:10:30 +0200 (CEST) Received: from saumur.act-europe.fr (saumur.act-europe.fr [10.10.0.183]) by mel.act-europe.fr (Postfix) with ESMTP id C2BB6CB02BD; Mon, 14 Jun 2010 12:10:30 +0200 (CEST) Received: by saumur.act-europe.fr (Postfix, from userid 525) id 94A95D9B31; Mon, 14 Jun 2010 12:10:37 +0200 (CEST) Date: Mon, 14 Jun 2010 12:10:37 +0200 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Robert Dewar Subject: [Ada] More accurate sloc information for pragma Check Message-ID: <20100614101037.GA8928@adacore.com> Mime-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.9i X-IsSubscribed: yes 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 adjusts the expansion for pragma Check so that the generated code has Sloc values referring to the condition expression, rather than the pragma keyword. The effect also applies to processing of pragma Precondition and Postcondition pragmas (as well as Assert/Check). This change is helpful for accurate coverage information. Given the test program: procedure ppc_sloc (X : Integer) is pragma Precondition (X >= 0); pragma Assert (X >= 0); begin null; end; Compile with -gnata -gnatGL, and with the patch, the output is: Source recreated from tree for ppc_sloc (body) -- 1: procedure ppc_sloc (X : Integer) is with system.system__assertions; procedure ppc_sloc (x : integer) is -- 2: pragma Precondition -- 3: (X >= 0); if not (x >= 0) then $system__assertions__raise_assert_failure ( "precondition failed at ppc_sloc.adb:3"); end if; -- 4: pragma Assert -- 5: (X >= 0); if not (x >= 0) then $system__assertions__raise_assert_failure ("ppc_sloc.adb:5"); end if; -- 6: begin begin -- 7: null; null; -- 8: end; return; end ppc_sloc; And as can be seen from this output, the generated if statement is associated with the condition rather than the pragma (without this patch, the if statements appear associated with the pragma line rather than the condition). Tested on x86_64-pc-linux-gnu, committed on trunk 2010-06-14 Robert Dewar * exp_prag.adb (Expand_Pragma_Check): Set Loc of generated code from condition. Index: exp_prag.adb =================================================================== --- exp_prag.adb (revision 160705) +++ exp_prag.adb (working copy) @@ -269,8 +269,8 @@ -------------------------- procedure Expand_Pragma_Check (N : Node_Id) is - Loc : constant Source_Ptr := Sloc (N); Cond : constant Node_Id := Arg2 (N); + Loc : constant Source_Ptr := Sloc (Cond); Nam : constant Name_Id := Chars (Arg1 (N)); Msg : Node_Id;