2020-06-04 Ed Schonberg <schonberg@adacore.com>
gcc/ada/
* sinput.adb (Sloc_Range): Ignore node in the tree if it appears
in a unit different from that of the node whose Sloc range we
are computing. This is necessary when computing the source range
of a subprogram body whose declaration includes a pre- or
postcondition, because declaration and body may appear in
different units, and the expanded code for the body includes
copies of the contract code.
procedure Sloc_Range (N : Node_Id; Min, Max : out Source_Ptr) is
+ Indx : constant Source_File_Index := Get_Source_File_Index (Sloc (N));
+
function Process (N : Node_Id) return Traverse_Result;
-- Process function for traversing the node tree
Orig : constant Node_Id := Original_Node (N);
begin
+ -- Skip nodes that may have been added during expansion and
+ -- that originate in other units, such as code for contracts
+ -- in subprogram bodies.
+
+ if Get_Source_File_Index (Sloc (Orig)) /= Indx then
+ return Skip;
+ end if;
+
if Sloc (Orig) < Min then
if Sloc (Orig) > No_Location then
Min := Sloc (Orig);