File tree Expand file tree Collapse file tree 5 files changed +51
-1
lines changed
testsuite/tests/instr-cov/c_metaprog Expand file tree Collapse file tree 5 files changed +51
-1
lines changed Original file line number Diff line number Diff line change 1+ int
2+ main ()
3+ {
4+ int a = 0 ;
5+ #define DECISION a
6+ #include "meta_print_msg.h"
7+ return 0 ;
8+ }
Original file line number Diff line number Diff line change 1+ #include <stdio.h>
2+
3+ #ifdef DECISION
4+ if (DECISION )
5+ printf ("Hello world!\n" );
6+ #endif
Original file line number Diff line number Diff line change 1+ bin-traces DEAD Check instrumentation-specific behavior
2+
Original file line number Diff line number Diff line change 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 ()
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments