Skip to content

Commit 07b55fc

Browse files
committed
SC_Obligations: fix loading of scopes for ignored source files
This fixes an assertion failure: when remapping source files from the scopes loaded from a SID/checkpoint, scopes whose identifier references ignored source files will lose their identifier. Such scopes will remain, but users will not be able to mark them of interest.
1 parent 792d43b commit 07b55fc

File tree

5 files changed

+66
-14
lines changed

5 files changed

+66
-14
lines changed

testsuite/tests/subp_of_interest/src/pkg.adb

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,34 @@
11
with Ada.Text_IO; use Ada.Text_IO;
22

33
package body Pkg is
4+
5+
---------
6+
-- Foo --
7+
---------
8+
49
procedure Foo (I : Integer) is
510
begin
611
Put_Line ("Hello from Foo!");
712
end Foo;
813

14+
---------
15+
-- Bar --
16+
---------
17+
918
procedure Bar is
1019
procedure Nested_Bar_1 is null;
20+
procedure Nested_Bar_2;
21+
1122
Dummy_Decl : Boolean;
12-
procedure Nested_Bar_2 is null;
23+
24+
------------------
25+
-- Nested_Bar_2 --
26+
------------------
27+
28+
procedure Nested_Bar_2 is
29+
begin
30+
Put_Line ("Hello from Nested_Bar_2!");
31+
end Nested_Bar_2;
1332
begin
1433
Nested_Bar_1;
1534
Nested_Bar_2;

testsuite/tests/subp_of_interest/src/pkg.ads

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ pragma Ada_2012;
33
package Pkg is
44
procedure Foo (I : Integer) with Pre => I > 0;
55
procedure Bar;
6+
7+
I : Integer;
68
end Pkg;

testsuite/tests/subp_of_interest/test.py

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,16 @@ def check_xcov(label, args, expected_output=""):
5353
# that the coverage report contains only coverage data for the specified
5454
# subprograms for source traces. For binary traces, simply check that the
5555
# gnatcov coverage invocation yields the expected warning.
56+
ckpt_filename = "trace.ckpt"
5657
check_xcov(
5758
"xcov_subp",
5859
cov_args
5960
+ [
6061
"--save-checkpoint",
61-
"trace.ckpt",
62+
ckpt_filename,
6263
f"--subprograms={pkg_spec}:4",
63-
f"--subprograms={pkg_body}:10",
64-
f"--subprograms={pkg_body}:12",
64+
f"--subprograms={pkg_body}:19",
65+
f"--subprograms={pkg_body}:20",
6566
],
6667
expected_output=(
6768
""
@@ -70,12 +71,14 @@ def check_xcov(label, args, expected_output=""):
7071
" with binary traces."
7172
),
7273
)
74+
cov_ckpt_args = cov_args[:-1] + ["--checkpoint", ckpt_filename]
7375
if src_traces:
7476
check_xcov_reports(
7577
"*.xcov",
7678
{
7779
"main.adb.xcov": {},
78-
"pkg.adb.xcov": {"+": {6, 10, 12}},
80+
"pkg.ads.xcov": {},
81+
"pkg.adb.xcov": {"+": {11, 19, 30}},
7982
},
8083
"xcov_subp",
8184
)
@@ -84,20 +87,37 @@ def check_xcov(label, args, expected_output=""):
8487
# specific subprogram. To do this, produce a new coverage report from the
8588
# checkpoint without using the --subprograms switch.
8689
thistest.log("== xcov_no_subp ==")
87-
check_xcov(
88-
"xcov_no_subp",
89-
cov_args[:-1]
90-
+ ["--checkpoint", "trace.ckpt"],
91-
)
90+
check_xcov("xcov_no_subp", cov_ckpt_args)
9291
check_xcov_reports(
9392
"*.xcov",
9493
{
9594
"main.adb.xcov": {"-": {5, 6}},
96-
"pkg.adb.xcov": {"+": {6, 10, 12}, "-": {11, 14, 15, 16}},
95+
"pkg.ads.xcov": {"-": {7}},
96+
"pkg.adb.xcov": {"+": {11, 19, 30}, "-": {22, 33, 34, 35}},
9797
},
9898
"xcov_no_subp",
9999
)
100100

101+
# Check that we can still select subprograms of interest declared in the
102+
# package body, when the package specification is ignored through
103+
# --ignored-source-files.
104+
thistest.log("== xcov_ignore ==")
105+
check_xcov(
106+
"xcov_ignore",
107+
cov_args + [
108+
f"--subprograms={pkg_body}:20",
109+
"--ignore-source-files=pkg.ads",
110+
],
111+
)
112+
check_xcov_reports(
113+
"*.xcov",
114+
{
115+
"main.adb.xcov": {},
116+
"pkg.adb.xcov": {"+": {30}},
117+
},
118+
"xcov_ignore",
119+
)
120+
101121
# Also check the warnings when the subprogram switch is ill-formed
102122

103123
# Case 1: missing colon in the argument

tools/gnatcov/sc_obligations.adb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,15 +1232,23 @@ package body SC_Obligations is
12321232
for Scope_Ent of CP_CU.Scope_Entities loop
12331233
Remap_SCO_Id (Scope_Ent.From);
12341234
Remap_SCO_Id (Scope_Ent.To);
1235-
Remap_SFI (Relocs, Scope_Ent.Identifier.Decl_SFI);
1235+
1236+
-- Scopes whose identifier references ignored source files will
1237+
-- lose their identifier: such scopes will remain, but users will
1238+
-- not be able to mark them of interest.
1239+
1240+
if SFI_Ignored (Relocs, Scope_Ent.Identifier.Decl_SFI) then
1241+
Scope_Ent.Identifier := No_Scope_Entity_Identifier;
1242+
else
1243+
Remap_SFI (Relocs, Scope_Ent.Identifier.Decl_SFI);
1244+
end if;
12361245

12371246
-- Register each scope identifiers to make them available to users
12381247
-- on the command line.
12391248

12401249
Available_Subps_Of_Interest.Include (Scope_Ent.Identifier);
12411250
end loop;
12421251
pragma Assert (SCOs_Nested_And_Ordered (CP_CU.Scope_Entities));
1243-
12441252
end if;
12451253

12461254
-- Preallocate line table entries for last file

tools/gnatcov/sc_obligations.ads

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ package SC_Obligations is
177177
-- and line for the original declaration (which is the body declaration for
178178
-- C/C++ and the specification declaration for Ada).
179179

180+
No_Scope_Entity_Identifier : constant Scope_Entity_Identifier :=
181+
(Decl_SFI => No_Source_File, Decl_Line => 0);
182+
180183
function "<" (L, R : Scope_Entity_Identifier) return Boolean is
181184
(if L.Decl_SFI = R.Decl_SFI
182185
then L.Decl_Line < R.Decl_Line
@@ -271,7 +274,7 @@ package SC_Obligations is
271274
To => No_SCO_Id,
272275
Name => +"",
273276
Sloc => No_Local_Location,
274-
Identifier => (Decl_SFI => 0, Decl_Line => 0));
277+
Identifier => No_Scope_Entity_Identifier);
275278

276279
type Any_SCO_Kind is (Removed, Statement, Decision, Condition, Operator);
277280
subtype SCO_Kind is Any_SCO_Kind range Statement .. Operator;

0 commit comments

Comments
 (0)