@@ -150,6 +150,8 @@ package body Instrument.C is
150150 -- Convert low level SCOs in each scope for each file to high-level SCOs
151151 -- using the mapping in SCO_Map. Set the file's SCO range to cover all of
152152 -- its scopes' SCO ranges.
153+ --
154+ -- Also remove from the Scopes map empty file scopes.
153155
154156 overriding procedure Append_SCO
155157 (Pass : Instrument_Pass_Kind;
@@ -491,10 +493,6 @@ package body Instrument.C is
491493 UIC : in out C_Unit_Inst_Context'Class;
492494 N : Cursor_T)
493495 is
494- Inserted : Boolean;
495-
496- File_Scope_Position : Scopes_In_Files_Map.Cursor;
497-
498496 procedure Enter_File_Scope
499497 (UIC : in out C_Unit_Inst_Context'Class;
500498 SFI : Source_File_Index)
@@ -508,7 +506,11 @@ package body Instrument.C is
508506
509507 procedure Enter_File_Scope
510508 (UIC : in out C_Unit_Inst_Context'Class;
511- SFI : Source_File_Index) is
509+ SFI : Source_File_Index)
510+ is
511+ File_Scope_Position : Scopes_In_Files_Map.Cursor;
512+
513+ Inserted : Boolean;
512514 begin
513515 if not UIC.Scopes.Contains (SFI) then
514516
@@ -629,24 +631,26 @@ package body Instrument.C is
629631
630632 procedure Remap_Scopes
631633 (Scopes : in out Scopes_In_Files_Map.Map;
632- SCO_Map : LL_HL_SCO_Map) is
634+ SCO_Map : LL_HL_SCO_Map)
635+ is
636+ Res : Scopes_In_Files_Map.Map;
633637 begin
634638 for Cur in Scopes.Iterate loop
635639 declare
636- Ref : constant Scopes_In_Files_Map.Reference_Type :=
637- Scopes.Reference (Cur);
638- File_Scope : Scope_Entity renames
639- Scope_Entities_Trees.Element (Ref .File_Scope_Entity);
640+ File_Scope : File_Scope_Type :=
641+ Scopes_In_Files_Map.Element (Cur);
642+ File_Scope_Entity : Scope_Entity renames
643+ Scope_Entities_Trees.Element (File_Scope .File_Scope_Entity);
640644 begin
641- -- If the file scope is empty, remove it
645+ -- If the file scope is empty, do not add it to the resulting map
642646
643- if File_Scope.To < File_Scope.From then
644- Ref.Scope_Entities.Delete_Subtree (Ref.File_Scope_Entity);
645- else
646- Remap_Scope_Entities (Ref.Scope_Entities, SCO_Map);
647+ if File_Scope_Entity.To >= File_Scope_Entity.From then
648+ Remap_Scope_Entities (File_Scope.Scope_Entities, SCO_Map);
649+ Res.Insert (Scopes_In_Files_Map.Key (Cur), File_Scope);
647650 end if ;
648651 end ;
649652 end loop ;
653+ Scopes := Res;
650654 end Remap_Scopes ;
651655
652656 -- --------------
0 commit comments