Skip to content

Commit a51c1c4

Browse files
committed
Merge branch 'eyraud/fix_metaprog_inst' into 'master'
Instrument.C: fix issue related to metaprogramming instances See merge request eng/cov/gnatcoverage!257 Do not instrument decisions in sources of interest whose parent statement does not belong to a source of interest. This can happen with metaprogramming instances in C/C++. Ref: eng/cov/gnatcoverage#103
2 parents 6509b2c + 6f835ae commit a51c1c4

File tree

5 files changed

+51
-1
lines changed

5 files changed

+51
-1
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
int
2+
main ()
3+
{
4+
int a = 0;
5+
#define DECISION a
6+
#include "meta_print_msg.h"
7+
return 0;
8+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <stdio.h>
2+
3+
#ifdef DECISION
4+
if (DECISION)
5+
printf("Hello world!\n");
6+
#endif
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bin-traces DEAD Check instrumentation-specific behavior
2+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
Checks that gnatcov does not instrument decisions in sources of interest whose
3+
parent statement does not belong to a source of interest. This can happen with
4+
metaprogramming instances in C/C++.
5+
"""
6+
7+
from SCOV.minicheck import build_run_and_coverage, check_xcov_reports
8+
from SUITE.context import thistest
9+
from SUITE.cutils import Wdir
10+
from SUITE.gprutils import GPRswitches
11+
from SUITE.tutils import gprfor
12+
13+
14+
tmp = Wdir("tmp_")
15+
16+
build_run_and_coverage(
17+
gprsw=GPRswitches(root_project=gprfor(srcdirs=[".."], mains=["main.c"])),
18+
covlevel="stmt+decision",
19+
mains=["main"],
20+
extra_instr_args=["--ignore-source-files=meta_print_msg.h"],
21+
extra_coverage_args=["-axcov"],
22+
trace_mode="src",
23+
)
24+
25+
check_xcov_reports("obj/*.xcov", {"obj/main.c.xcov": {"+": {4, 7}}})
26+
27+
thistest.result()

tools/gnatcov/instrument-c.adb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1951,6 +1951,13 @@ package body Instrument.C is
19511951
Append (Trailing_Braces, '}');
19521952
end if;
19531953

1954+
-- If this statement does not belong to a source of interest, skip
1955+
-- it altogether.
1956+
1957+
if Is_Null (N) or not Is_Source_Of_Interest (UIC, N) then
1958+
return;
1959+
end if;
1960+
19541961
-- Initialize or extend current statement sequence. Note that for
19551962
-- special cases such as IF and SWITCH statements we will modify
19561963
-- the range to exclude internal statements that should not be
@@ -2248,7 +2255,7 @@ package body Instrument.C is
22482255
-- statement source location range.
22492256

22502257
begin
2251-
if Is_Null (N) or else not Is_Source_Of_Interest (UIC, N) then
2258+
if Is_Null (N) then
22522259
return;
22532260
end if;
22542261

0 commit comments

Comments
 (0)