Skip to content

Commit 9b81258

Browse files
author
Viviane Garèse
committed
Do not instrument static values as calls
1 parent 283e584 commit 9b81258

File tree

16 files changed

+100
-16
lines changed

16 files changed

+100
-16
lines changed

testsuite/tests/287-function_call_cov/contracts/src/test_contracts_not_called.adb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ end Test_Contracts_Not_Called;
1111
-- /pre/ l- ## a-
1212
--# contracts.adb
1313
-- /foo/ l- ## f-
14-
-- /t/ l- ## s-,f-,c-
14+
-- /t/ l- ## s-,f-
1515
-- /assert/ l- ## s-,c-,c-
1616
-- /null/ l- ## s-

testsuite/tests/287-function_call_cov/dotted_type/src/make_call.adb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ begin
4545
/= 0 -- # deci
4646
and then -- # deci
4747
Pkg5.F.B) -- # p_pkg5
48-
and then False -- # p_call
48+
and then False -- # false
4949
then
5050
null; -- # null
5151
end if;

testsuite/tests/287-function_call_cov/dotted_type/src/test_dotted_type.adb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ end Test_Dotted_Type;
2121
-- /d_nf1/ l! ## 0
2222
-- /deci/ l! ## 0
2323
-- /v_dec/ l- ## 0
24-
-- /p_call/ l! ## c-
2524
-- /p_pkg5/ l! ## c?
25+
-- /false/ l+ ## 0
2626
-- /null/ l- ## s-
2727
--# pkg4.ads
2828
-- /decl/ l+ ## 0

testsuite/tests/287-function_call_cov/nested_calls/src/nested.adb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ begin
2626
B -- # v_call
2727
(B -- # v_call
2828
(B), -- # v_call
29-
False); -- # v_call
29+
False); -- # v_false
3030
end if;
3131

3232
end Nested;

testsuite/tests/287-function_call_cov/nested_calls/src/test_nested.adb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ begin
1010
end Test_Nested;
1111

1212
--# nested.adb
13-
-- /stmt/ l+ ## 0
14-
-- /fun/ l+ ## 0
15-
-- /call/ l+ ## 0
16-
-- /if/ l! ## dT-
17-
-- /v_stmt/ l- ## s-
18-
-- /v_call/ l- ## s=>s-, f=>c-
13+
-- /stmt/ l+ ## 0
14+
-- /fun/ l+ ## 0
15+
-- /call/ l+ ## 0
16+
-- /if/ l! ## dT-
17+
-- /v_stmt/ l- ## s-
18+
-- /v_call/ l- ## f=>c-
19+
-- /v_false/ l- ## 0

testsuite/tests/287-function_call_cov/protected_body/src/test_not_called.adb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ end Test_Not_Called;
1515
-- /decl/ l+ ## 0
1616
--# foo.adb
1717
-- /fun/ l- ## f-
18-
-- /expr_fun/ l- ## s=>s-, f=>s-,f-,c-
18+
-- /expr_fun/ l- ## s=>s-, f=>s-,f-
1919
-- /call_stmt/ f=>l- ## s=>s-, f=>s-,c-
2020
-- /stmt/ l- ## s-
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
pragma Ada_2012;
2+
3+
procedure Discriminant is
4+
type Color is (Red, Green, Blue, Not_On); -- # a
5+
6+
type Disc_Rec (Disc : Color) is -- # a
7+
record
8+
null; -- # a
9+
end record;
10+
11+
My_Rec : constant Disc_Rec := (Disc => Red); -- # a
12+
begin
13+
null;
14+
end Discriminant;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
pragma Ada_2012;
2+
3+
procedure Enum is
4+
type Color is (Red, Green, Blue, Not_On); -- # decl
5+
6+
Pixel_1 : Color := Red; -- # decl
7+
Pixel_2 : Color := Green; -- # decl
8+
Pixel_3 : Color := Blue; -- # decl
9+
10+
Nb_Red : Integer := 0; -- # decl
11+
begin
12+
13+
-- In an if statement
14+
if Pixel_1 not in Red then -- # if
15+
Nb_Red := Nb_Red + 1; -- # stmt_no
16+
end if;
17+
18+
-- In a case expression
19+
Nb_Red := Nb_Red + -- # stmt_yes
20+
(case Pixel_2 is -- # stmt_yes
21+
when Red => 1, -- # stmt_yes
22+
when Green .. Green => 0, -- # stmt_yes
23+
when Blue | Not_On => 0); -- # stmt_yes
24+
25+
-- In a case statement
26+
case Pixel_3 is -- # stmt_yes
27+
when Red => Nb_Red := Nb_Red + 1; -- # stmt_no
28+
when Green .. Green => null; -- # stmt_no
29+
when Blue | Not_On => null; -- # stmt_yes
30+
end case;
31+
end Enum;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
with Discriminant;
2+
3+
-- Test that the use of enum values, which are calls, are not instrumented as
4+
-- calls. This is checked with an enum value used in a record discriminant
5+
-- that needs it to be a static value. Instrumenting it as a call would
6+
-- result in a compilation error as they would no longer be static.
7+
8+
procedure Test_Discriminant is
9+
begin
10+
Discriminant;
11+
end Test_Discriminant;
12+
13+
--# discriminant.adb
14+
-- /a/ l+ ## 0
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
with Enum;
2+
3+
-- Test that the use of enum values, which are calls, are not instrumented as
4+
-- calls. This is checked with enum values used in case statements that need
5+
-- them to be static values. Instrumenting them as calls would result in a
6+
-- compilation error as they would no longer be static.
7+
8+
procedure Test_Enum is
9+
begin
10+
Enum;
11+
end Test_Enum;
12+
13+
--# enum.adb
14+
-- /decl/ l+ ## 0
15+
-- /if/ l! ## dT-
16+
-- /stmt_no/ l- ## s-
17+
-- /stmt_yes/ l+ ## 0
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from SCOV.tc import TestCase
2+
from SCOV.tctl import CAT
3+
from SUITE.context import thistest
4+
5+
6+
TestCase(category=CAT.mcdc, fun_call_lvl=True).run()
7+
thistest.result()

testsuite/tests/287-function_call_cov/subp_kinds/src/no_decls_called.adb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ begin
101101
-- statement violations.
102102
Proc; -- # v_stmt
103103
Proc_Param (Dummy); -- # v_stmt
104-
Proc_Param (Dummy, False); -- # v_cstmt
104+
Proc_Param (Dummy, False); -- # v_stmt
105105
Over (5); -- # v_stmt
106106
Over (1, 2); -- # v_stmt
107107
end if;

testsuite/tests/287-function_call_cov/subp_kinds/src/test_no_decls_called.adb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,5 @@ end Test_No_Decls_Called;
1717
-- /if_cond/ l! ## dT-
1818
-- /v_dummy/ l- ## s-
1919
-- /v_stmt/ l- ## s-,c-
20-
-- /v_cstmt/ l- ## s-,c-,c-
2120
-- /v_call/ l- ## c-
2221
-- /v_scall/ l- ## s=>s-, f=>s-,c-

testsuite/tests/287-function_call_cov/subp_kinds_with_decls/src/call_with_decls.adb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ begin
5353
-- statement violations.
5454
Proc; -- # v_cstmt
5555
Proc_Param (Dummy); -- # v_cstmt
56-
Proc_Param (Dummy, False); -- # v_false
56+
Proc_Param (Dummy, False); -- # v_cstmt
5757
Over (5); -- # v_cstmt
5858
Over (1, 2); -- # v_cstmt
5959
end if;

testsuite/tests/287-function_call_cov/subp_kinds_with_decls/src/test_with_decls_called.adb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ end Test_With_Decls_Called;
1616
-- /v_fun/ l- ## c-
1717
-- /v_sfun/ l- ## s-,c-
1818
-- /v_cstmt/ l- ## s-,c-
19-
-- /v_false/ l- ## s-,c-,c-
2019
--# with_decls.ads
2120
-- /stmt/ l+ ## 0
2221
--# with_decls.adb

tools/gnatcov/instrument-ada_unit.adb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6145,7 +6145,9 @@ package body Instrument.Ada_Unit is
61456145
is
61466146
Full_Call_Node : Ada_Node;
61476147
begin
6148-
if Is_Call_Leaf (Node) then
6148+
if Is_Call_Leaf (Node)
6149+
and then not Is_Static_Expr (Node.As_Expr)
6150+
then
61496151
Full_Call_Node := Full_Call (Node);
61506152

61516153
-- Skip calls that are direct children of call statements

0 commit comments

Comments
 (0)