From patchwork Mon Jun 14 10:10:37 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [Ada] More accurate sloc information for pragma Check Date: Mon, 14 Jun 2010 00:10:37 -0000 From: Arnaud Charlet X-Patchwork-Id: 55509 Message-Id: <20100614101037.GA8928@adacore.com> To: gcc-patches@gcc.gnu.org Cc: Robert Dewar 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;