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;