Skip to content

Commit 674626c

Browse files
committed
Merge branch 'eyraud/315' into 'master'
Fix detection of non-instrumentable expression function Closes #315 and #344 See merge request eng/das/cov/gnatcoverage!622 Closes eng/das/cov/gnatcoverage#315 Closes eng/das/cov/gnatcoverage#344
2 parents fea53e0 + 01b9818 commit 674626c

File tree

12 files changed

+83
-108
lines changed

12 files changed

+83
-108
lines changed

testsuite/tests/instr-cov/expr_func/prim2/main.adb renamed to testsuite/tests/instr-cov/expr_func/completion/main.adb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ pragma Ada_2012;
22
with Pak; use Pak;
33

44
procedure Main is
5-
Obj : T := Make (True);
6-
Obj2 : TT := Make (False);
5+
T_Instance : T := Make (True);
76
begin
87
null;
98
end Main;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
pragma Ada_2012;
2+
3+
package Pak is
4+
5+
type T is private;
6+
7+
function Make (Cond : Boolean) return T;
8+
9+
private
10+
type T is tagged record
11+
X : Integer;
12+
end record;
13+
function Make (Cond : Boolean) return T is (T'(X => (if Cond then 1 else 2)));
14+
15+
type TT is new T with record
16+
Y : Integer;
17+
end record;
18+
overriding function Make (Cond : Boolean) return TT is (TT'(X => 3, Y => 4));
19+
end Pak;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
Regression test: check that gnatcov does not instrument expression function
3+
that are a primitive of a tagged type T when the controlling parameter is the
4+
return type, and when the expression function is a completion.
5+
6+
gnatcov used to instrument such expression function, which resulted in
7+
introducing a new primitive (the wrapper generated for MC/DC instrumentation),
8+
which was not defined for derived types.
9+
"""
10+
11+
from SCOV.minicheck import build_run_and_coverage, check_xcov_reports
12+
from SUITE.context import thistest
13+
from SUITE.cutils import Wdir
14+
from SUITE.gprutils import GPRswitches
15+
from SUITE.tutils import gprfor
16+
17+
18+
tmp = Wdir("tmp_")
19+
20+
build_run_and_coverage(
21+
gprsw=GPRswitches(root_project=gprfor(srcdirs=[".."], mains=["main.adb"])),
22+
covlevel="stmt+uc_mcdc",
23+
mains=["main"],
24+
extra_coverage_args=["-axcov", "--output-dir=xcov"],
25+
trace_mode="src",
26+
tolerate_instrument_messages=(
27+
"cannot instrument an expression function which"
28+
),
29+
)
30+
31+
check_xcov_reports(
32+
"xcov",
33+
{
34+
"main.adb.xcov": {"+": {5, 7}},
35+
"pak.ads.xcov": {"+": {5, 10, 11, 12, 15, 16, 17}, "?": {13, 18}},
36+
},
37+
)
38+
39+
thistest.result()

testsuite/tests/instr-cov/expr_func/prim/p.gpr

Lines changed: 0 additions & 4 deletions
This file was deleted.

testsuite/tests/instr-cov/expr_func/prim/test.opt

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,39 @@
11
"""
2-
Check that we properly instrument expression functions that are primitives
3-
of tagged types for MC/DC.
2+
Check that gnatcov correctly processes expression functions that are primitives
3+
of tagged types for MC/DC, e.g. it warns about them, and they are reported as
4+
uninstrumented in the coverage report.
45
"""
56

6-
import os
7-
import os.path
8-
97
from SCOV.minicheck import build_run_and_coverage, check_xcov_reports
108
from SUITE.context import thistest
119
from SUITE.cutils import Wdir
1210
from SUITE.gprutils import GPRswitches
11+
from SUITE.tutils import gprfor
1312

1413

15-
p_gpr = os.path.abspath("p.gpr")
16-
obj_dir = os.path.abspath("obj")
17-
1814
tmp = Wdir("tmp_")
1915

2016
build_run_and_coverage(
21-
gprsw=GPRswitches(root_project=p_gpr),
17+
gprsw=GPRswitches(root_project=gprfor(srcdirs=[".."], mains=["main.adb"])),
2218
covlevel="stmt+uc_mcdc",
2319
mains=["main"],
2420
extra_coverage_args=["-axcov", "--output-dir=xcov"],
25-
gpr_obj_dir=obj_dir,
26-
gpr_exe_dir=obj_dir,
2721
trace_mode="src",
22+
tolerate_instrument_messages=(
23+
"cannot instrument an expression function which"
24+
),
2825
)
2926

30-
# TODO: update coverage expectations once compiler bug
31-
# has been fixed and XFAIL is removed.
32-
3327
check_xcov_reports(
34-
"xcov", {"main.adb.xcov": {"+": {4, 5, 7, 12, 14, 17, 19, 21, 22, 23, 24}}}
28+
"xcov",
29+
{
30+
"main.adb.xcov": {"+": {6}},
31+
"pak.ads.xcov": {
32+
"+": {4, 5, 6, 13, 14, 15},
33+
"-": {8, 10},
34+
"?": {11, 16},
35+
},
36+
},
3537
)
3638

3739
thistest.result()

testsuite/tests/instr-cov/expr_func/prim2/p.gpr

Lines changed: 0 additions & 4 deletions
This file was deleted.

testsuite/tests/instr-cov/expr_func/prim2/pak.adb

Lines changed: 0 additions & 10 deletions
This file was deleted.

testsuite/tests/instr-cov/expr_func/prim2/pak.ads

Lines changed: 0 additions & 25 deletions
This file was deleted.

testsuite/tests/instr-cov/expr_func/prim2/test.opt

Lines changed: 0 additions & 1 deletion
This file was deleted.

testsuite/tests/instr-cov/expr_func/prim2/test.py

Lines changed: 0 additions & 44 deletions
This file was deleted.

tools/gnatcov/instrument-ada_unit.adb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3023,8 +3023,13 @@ package body Instrument.Ada_Unit is
30233023
if Common_Nodes.Ctrl_Type.Is_Null then
30243024
return False;
30253025
end if;
3026-
return Common_Nodes.N_Spec.F_Subp_Returns.P_Designated_Type_Decl
3027-
= Common_Nodes.Ctrl_Type;
3026+
3027+
-- Always compare the full views, to avoid an equality mismatch when
3028+
-- e.g. comparing the full view against an incomplete view.
3029+
3030+
return
3031+
Common_Nodes.N_Spec.F_Subp_Returns.P_Designated_Type_Decl.P_Full_View
3032+
= Common_Nodes.Ctrl_Type.P_Full_View;
30283033
exception
30293034
when Exc : Property_Error =>
30303035
Report (UIC,

0 commit comments

Comments
 (0)