Patchwork [Ada] More accurate sloc information for pragma Check

login
register
mail settings
Submitter Arnaud Charlet
Date June 14, 2010, 10:10 a.m.
Message ID <20100614101037.GA8928@adacore.com>
Download mbox | patch
Permalink /patch/55509/
State New
Headers show

Comments

Arnaud Charlet - June 14, 2010, 10:10 a.m.
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  <dewar@adacore.com>

	* exp_prag.adb (Expand_Pragma_Check): Set Loc of generated code from
	condition.

Patch

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;