Skip to content

Commit d1ffb4f

Browse files
committed
SC_Obligations: ensure that Traverse_SCO is called with increasing SCOs
1 parent b458dab commit d1ffb4f

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

tools/gnatcov/sc_obligations.adb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,7 @@ package body SC_Obligations is
664664
Result.Scope_Stack := Scope_Stacks.Empty_List;
665665
Result.Active_Scopes := Scope_Id_Sets.Empty;
666666
Set_Active_Scope_Ent (Result, Result.It.First);
667+
Result.Last_SCO := No_SCO_Id;
667668
return Result;
668669
end Scope_Traversal;
669670

@@ -674,6 +675,8 @@ package body SC_Obligations is
674675
procedure Traverse_SCO (ST : in out Scope_Traversal_Type; SCO : SCO_Id) is
675676
use Scope_Entities_Trees;
676677
begin
678+
ST.Last_SCO := SCO;
679+
677680
-- In some cases (C metaprogramming instances), e.g.
678681
--
679682
-- foo.h:
@@ -733,6 +736,15 @@ package body SC_Obligations is
733736
end loop;
734737
end Traverse_SCO;
735738

739+
--------------
740+
-- Last_SCO --
741+
--------------
742+
743+
function Last_SCO (ST : Scope_Traversal_Type) return SCO_Id is
744+
begin
745+
return ST.Last_SCO;
746+
end Last_SCO;
747+
736748
--------------------------
737749
-- Set_Active_Scope_Ent --
738750
--------------------------

tools/gnatcov/sc_obligations.ads

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,20 @@ package SC_Obligations is
246246
-- Is_Active to know whether a given scope is active in the given
247247
-- traversal.
248248

249-
function Scope_Traversal (CU : CU_Id) return Scope_Traversal_Type;
249+
function Scope_Traversal (CU : CU_Id) return Scope_Traversal_Type
250+
with Post => Last_SCO (Scope_Traversal'Result) = No_SCO_Id;
250251
-- Return a scope traversal for the given compilation unit
251252

252-
procedure Traverse_SCO (ST : in out Scope_Traversal_Type; SCO : SCO_Id);
253+
procedure Traverse_SCO (ST : in out Scope_Traversal_Type; SCO : SCO_Id)
254+
with Pre => Last_SCO (ST) <= SCO,
255+
Post => Last_SCO (ST) = SCO;
253256
-- Traverse the given SCO and update the Scope_Traversal accordingly. Note
254257
-- that the scope traversal must be done on increasing SCOs identifiers.
255258

259+
function Last_SCO (ST : Scope_Traversal_Type) return SCO_Id;
260+
-- Return the last SCO that was passed to Traverse_SCO, or No_SCO_Id if
261+
-- Traverse_SCO has not been called yet on ST.
262+
256263
function Is_Active
257264
(ST : Scope_Traversal_Type;
258265
Subps_Of_Interest : Scope_Id_Set) return Boolean;
@@ -1376,6 +1383,11 @@ private
13761383

13771384
It : Iterator_Acc;
13781385
-- Iterator to traverse the scope tree
1386+
1387+
Last_SCO : SCO_Id;
1388+
-- Keep track of the last SCO requested with Traverse_SCO. We use this
1389+
-- to check that SCOs are requested in the right order (lower Ids to
1390+
-- higher ones).
13791391
end record;
13801392

13811393
procedure Set_Active_Scope_Ent
@@ -1389,6 +1401,7 @@ private
13891401
Active_Scopes => Scope_Id_Sets.Empty_Set,
13901402
Active_Scope_Ent => Scope_Entities_Trees.No_Element,
13911403
Next_Scope_Ent => Scope_Entities_Trees.No_Element,
1392-
It => null);
1404+
It => null,
1405+
Last_SCO => No_SCO_Id);
13931406

13941407
end SC_Obligations;

0 commit comments

Comments
 (0)