Skip to content

Commit 740aece

Browse files
committed
Fix detection of non-instrumentable expression function
1 parent fea53e0 commit 740aece

File tree

4 files changed

+73
-2
lines changed

4 files changed

+73
-2
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
pragma Ada_2012;
2+
with Pak; use Pak;
3+
4+
procedure Main is
5+
T_Instance : T := Make (True);
6+
begin
7+
null;
8+
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()

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)