diff mbox

[Ada] Debug information for code generated for pragma Check

Message ID 20130102093814.GA31164@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Jan. 2, 2013, 9:38 a.m. UTC
This change corrects an anomaly in the source locations produced in debug
information for code implementing a pragma Check that could cause incorrect
coverage analyses.

Tested on x86_64-pc-linux-gnu, committed on trunk

2013-01-02  Thomas Quinot  <quinot@adacore.com>

	* exp_prag.adb (Expand_Pragma_Check): The statements generated
	for the pragma must have the sloc of the pragma, not the
	sloc of the condition, otherwise this creates anomalies in the
	generated debug information that confuse coverage analysis tools.
diff mbox

Patch

Index: exp_prag.adb
===================================================================
--- exp_prag.adb	(revision 194781)
+++ exp_prag.adb	(working copy)
@@ -274,18 +274,18 @@ 
    --------------------------
 
    procedure Expand_Pragma_Check (N : Node_Id) is
+      Loc  : constant Source_Ptr := Sloc (N);
+      --  Location of the pragma node. Note: it is important to use this
+      --  location (and not the location of the expression) for the generated
+      --  statements, otherwise the implicit return statement in the body
+      --  of a pre/postcondition subprogram may inherit the source location
+      --  of part of the expression, which causes confusing debug information
+      --  to be generated, which interferes with coverage analysis tools.
+
       Cond : constant Node_Id := Arg2 (N);
       Nam  : constant Name_Id := Chars (Arg1 (N));
       Msg  : Node_Id;
 
-      Loc  : constant Source_Ptr := Sloc (First_Node (Cond));
-      --  Source location used in the case of a failed assertion. Note that
-      --  the source location of the expression is not usually the best choice
-      --  here. For example, it gets located on the last AND keyword in a
-      --  chain of boolean expressiond AND'ed together. It is best to put the
-      --  message on the first character of the assertion, which is the effect
-      --  of the First_Node call here.
-
    begin
       --  We already know that this check is enabled, because otherwise the
       --  semantic pass dealt with rewriting the assertion (see Sem_Prag)
@@ -362,7 +362,15 @@ 
 
          else
             declare
-               Msg_Loc : constant String := Build_Location_String (Loc);
+               Msg_Loc : constant String :=
+                           Build_Location_String (Sloc (First_Node (Cond)));
+               --  Source location used in the case of a failed assertion:
+               --  point to the failing condition, not Loc. Note that the
+               --  source location of the expression is not usually the best
+               --  choice here. For example, it gets located on the last AND
+               --  keyword in a chain of boolean expressiond AND'ed together.
+               --  It is best to put the message on the first character of the
+               --  condition, which is the effect of the First_Node call here.
 
             begin
                Name_Len := 0;