Skip to content

Commit ed88172

Browse files
committed
Refactor handling of not instrumented obligations
We had different ways of dealing with not instrumented statements, and decisions / conditions. Unify both for clarity purposes. Also move parts of the not instrumented obligations handling to Instrument.Common, to be able to use it in Instrument.C, as we will need it for constexpr code constructs.
1 parent 62e7d46 commit ed88172

File tree

7 files changed

+91
-126
lines changed

7 files changed

+91
-126
lines changed

tools/gnatcov/decision_map.adb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ package body Decision_Map is
8080
-- Return the PC of the first conditional branch instruction in D_Occ.
8181
-- Used as unique identifier for occurrences.
8282

83-
package SCO_Sets is new Ada.Containers.Ordered_Sets (SCO_Id);
84-
8583
type Call_Kind is (Normal, Raise_Exception, Finalizer);
8684
-- Classification of calls within a decision:
8785
-- - normal calls to subprograms

tools/gnatcov/instrument-ada_unit.adb

Lines changed: 50 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,6 @@ package body Instrument.Ada_Unit is
9696
return Ada_Qualified_Name;
9797
-- Convert a Libadalang fully qualified name into our format
9898

99-
procedure Import_Non_Instrumented_LL_SCOs
100-
(UIC : Ada_Unit_Inst_Context; SCO_Map : LL_HL_SCO_Map);
101-
-- Import the low level SCO in UIC marked as non-instrumented in the high
102-
-- level non-instrumented SCO_Id sets.
103-
10499
procedure Find_Ada_Units
105100
(Instrumenter : in out Ada_Instrumenter_Type;
106101
Filename : String;
@@ -165,29 +160,6 @@ package body Instrument.Ada_Unit is
165160
end return;
166161
end To_Qualified_Name;
167162

168-
-------------------------------------
169-
-- Import_Non_Instrumented_LL_SCOs --
170-
-------------------------------------
171-
172-
procedure Import_Non_Instrumented_LL_SCOs
173-
(UIC : Ada_Unit_Inst_Context; SCO_Map : LL_HL_SCO_Map) is
174-
begin
175-
for LL_SCO of UIC.Non_Instr_LL_SCOs loop
176-
declare
177-
Remapped_SCO : constant SCO_Id := SCO_Map (Nat (LL_SCO));
178-
begin
179-
case Kind (Remapped_SCO) is
180-
when Statement => Set_Stmt_SCO_Non_Instr (Remapped_SCO);
181-
when Decision => Set_Decision_SCO_Non_Instr (Remapped_SCO);
182-
when Condition => Set_Decision_SCO_Non_Instr_For_MCDC
183-
(Enclosing_Decision (Remapped_SCO));
184-
when others =>
185-
null;
186-
end case;
187-
end;
188-
end loop;
189-
end Import_Non_Instrumented_LL_SCOs;
190-
191163
type All_Symbols is
192164
(
193165
-- Aspects
@@ -2972,8 +2944,8 @@ package body Instrument.Ada_Unit is
29722944
-- top level).
29732945
--
29742946
-- If Do_Not_Instrument, this creates SCOs for the decisions/conditions,
2975-
-- but plan not to instrument them, so that the decision can be reported as
2976-
-- such.
2947+
-- but plans not to instrument them, so that the decision can be reported
2948+
-- as such.
29772949

29782950
--------------------------
29792951
-- Internal Subprograms --
@@ -3067,6 +3039,10 @@ package body Instrument.Ada_Unit is
30673039

30683040
In_Generic : Boolean := False;
30693041
-- Wether this statment is generic code.
3042+
3043+
Do_Not_Instrument : Boolean;
3044+
-- Whether this statement should not be instrumented. This is set to
3045+
-- True when instrumenting the statement could create invalid Ada code.
30703046
end record;
30713047

30723048
package SC is new Table.Table
@@ -3126,16 +3102,16 @@ package body Instrument.Ada_Unit is
31263102
SD_First : constant Nat := SD.Last + 1;
31273103
-- Record first entries used in SC/SD at this recursive level
31283104

3129-
Current_Insertion_Info : aliased Insertion_Info :=
3130-
(Method => None, Unsupported => False);
3105+
Current_Insertion_Info : aliased Insertion_Info := (Method => None);
31313106

31323107
procedure Extend_Statement_Sequence
31333108
(UIC : Ada_Unit_Inst_Context;
31343109
N : Ada_Node'Class;
31353110
Typ : Character;
31363111
Insertion_N : Node_Rewriting_Handle :=
31373112
No_Node_Rewriting_Handle;
3138-
Instrument_Location : Instrument_Location_Type := Before);
3113+
Instrument_Location : Instrument_Location_Type := Before;
3114+
Do_Not_Instrument : Boolean := False);
31393115
-- Extend the current statement sequence to encompass the node N.
31403116
--
31413117
-- Typ is the letter that identifies the type of statement/declaration
@@ -3206,7 +3182,8 @@ package body Instrument.Ada_Unit is
32063182
Typ : Character;
32073183
Insertion_N : Node_Rewriting_Handle :=
32083184
No_Node_Rewriting_Handle;
3209-
Instrument_Location : Instrument_Location_Type := Before)
3185+
Instrument_Location : Instrument_Location_Type := Before;
3186+
Do_Not_Instrument : Boolean := False)
32103187
is
32113188
SR : constant Source_Location_Range := N.Sloc_Range;
32123189

@@ -3344,7 +3321,8 @@ package body Instrument.Ada_Unit is
33443321
when others => After)
33453322
else Instrument_Location),
33463323

3347-
In_Generic => UIC.In_Generic));
3324+
In_Generic => UIC.In_Generic,
3325+
Do_Not_Instrument => Do_Not_Instrument));
33483326
end Extend_Statement_Sequence;
33493327

33503328
-----------------------------
@@ -3442,12 +3420,7 @@ package body Instrument.Ada_Unit is
34423420

34433421
Raise_Stub_Internal_Error_For (Ada_Instrument_Insert_Stmt_Witness);
34443422

3445-
-- If the current code pattern is actually unsupported, do not
3446-
-- even try to insert the witness call or allocate bits for it in
3447-
-- the buffers. Mark the corresponding SCO as non-instrumented
3448-
-- instead.
3449-
3450-
if Insert_Info.Unsupported then
3423+
if SCE.Do_Not_Instrument then
34513424
UIC.Non_Instr_LL_SCOs.Include (SCO_Id (LL_SCO_Id));
34523425
return;
34533426
end if;
@@ -3863,7 +3836,6 @@ package body Instrument.Ada_Unit is
38633836
begin
38643837

38653838
II.RH_List := Stmt_list_RH;
3866-
II.Unsupported := False;
38673839
II.Index := 1;
38683840
II.Rewriting_Offset := 0;
38693841
II.Preelab := False;
@@ -3951,8 +3923,7 @@ package body Instrument.Ada_Unit is
39513923
-- Witness insertion info for statements (for both null procedures
39523924
-- and expression functions).
39533925

3954-
Unsupported : Boolean := False;
3955-
-- Temporary to compute New_Insertion_Info.Unsupported
3926+
Do_Not_Instrument : Boolean := False;
39563927

39573928
EF_Inserter : aliased Expr_Func_MCDC_State_Inserter :=
39583929
(N_Spec => N_Spec,
@@ -3989,7 +3960,7 @@ package body Instrument.Ada_Unit is
39893960

39903961
if Is_Generic (UIC, N.As_Basic_Decl) then
39913962
if Is_Expr_Function then
3992-
Unsupported := True;
3963+
Do_Not_Instrument := True;
39933964
Report (UIC, N,
39943965
"gnatcov limitation: "
39953966
& "cannot instrument generic expression functions."
@@ -4000,7 +3971,7 @@ package body Instrument.Ada_Unit is
40003971
-- functions and null procedures, we are in the case of a
40013972
-- generic null procedure here.
40023973

4003-
Unsupported := True;
3974+
Do_Not_Instrument := True;
40043975
Report (UIC, N,
40053976
"gnatcov limitation:"
40063977
& " cannot instrument generic null procedures."
@@ -4036,7 +4007,7 @@ package body Instrument.Ada_Unit is
40364007
-- so that the augmented EF is no longer a primitive of its
40374008
-- return type. Need to check for potential freezing issues.
40384009

4039-
Unsupported := True;
4010+
Do_Not_Instrument := True;
40404011
Report (UIC, N,
40414012
"gnatcov limitation:"
40424013
& " cannot instrument an expression function which is"
@@ -4047,7 +4018,7 @@ package body Instrument.Ada_Unit is
40474018
elsif Is_Self_Referencing (UIC, N.As_Expr_Function)
40484019
and then not Common_Nodes.Ctrl_Type.Is_Null
40494020
then
4050-
Unsupported := True;
4021+
Do_Not_Instrument := True;
40514022
Report (UIC, N,
40524023
"gnatcov limitation:"
40534024
& " instrumenting a self referencing (i.e. recursive)"
@@ -4086,11 +4057,10 @@ package body Instrument.Ada_Unit is
40864057

40874058
New_Insertion_Info :=
40884059
(Method => Expression_Function,
4089-
Unsupported => Unsupported,
40904060
Witness_Actual => No_Node_Rewriting_Handle,
40914061
Witness_Formal => No_Node_Rewriting_Handle);
40924062

4093-
if not New_Insertion_Info.Unsupported then
4063+
if not Do_Not_Instrument then
40944064

40954065
-- Pass all expression function parameters to the augmented
40964066
-- expression function call.
@@ -4124,7 +4094,6 @@ package body Instrument.Ada_Unit is
41244094

41254095
New_Insertion_Info :=
41264096
(Method => Statement,
4127-
Unsupported => Unsupported,
41284097
RH_List => NP_Nodes.Stmt_List,
41294098
Index => 1,
41304099
Rewriting_Offset => 0,
@@ -4153,29 +4122,21 @@ package body Instrument.Ada_Unit is
41534122
declare
41544123
N_Expr : constant Expr := N.As_Expr_Function.F_Expr;
41554124
begin
4156-
Extend_Statement_Sequence (UIC, N_Expr, 'X');
4157-
4158-
-- For unsupported expression functions, creating a statement
4159-
-- obligation is enough: it will never be satisfied and thus
4160-
-- violations regarding conditions/decisions will not be
4161-
-- displayed, so no need to bother creating them and adding
4162-
-- special cases in decision processings for unsupported
4163-
-- expression functions.
4164-
4165-
if not New_Insertion_Info.Unsupported then
4166-
Process_Decisions_Defer (N_Expr, 'X');
4167-
end if;
4125+
Extend_Statement_Sequence
4126+
(UIC, N_Expr, 'X', Do_Not_Instrument => Do_Not_Instrument);
4127+
Process_Decisions_Defer (N_Expr, 'X', Do_Not_Instrument);
41684128
end;
41694129
else
41704130
-- Even though there is a "null" keyword in the null procedure,
41714131
-- is no dedicated node for it in the Libadalang parse tree: use
41724132
-- the whole null procedure declaration to provide a sloc.
41734133

41744134
Extend_Statement_Sequence
4175-
(UIC => UIC,
4176-
N => N,
4177-
Typ => 'X',
4178-
Insertion_N => NP_Nodes.Null_Stmt);
4135+
(UIC => UIC,
4136+
N => N,
4137+
Typ => 'X',
4138+
Insertion_N => NP_Nodes.Null_Stmt,
4139+
Do_Not_Instrument => Do_Not_Instrument);
41794140
end if;
41804141
Set_Statement_Entry;
41814142

@@ -4187,7 +4148,7 @@ package body Instrument.Ada_Unit is
41874148
-- There is nothing else to do if we gave up instrumenting this
41884149
-- subprogram.
41894150

4190-
if New_Insertion_Info.Unsupported then
4151+
if Do_Not_Instrument then
41914152
return;
41924153
end if;
41934154

@@ -5171,7 +5132,6 @@ package body Instrument.Ada_Unit is
51715132
else Declaration);
51725133
II : Insertion_Info (Method);
51735134
begin
5174-
II.Unsupported := False;
51755135
II.RH_List := Handle (L);
51765136
II.Index := 0;
51775137
II.Rewriting_Offset := 0;
@@ -5686,7 +5646,6 @@ package body Instrument.Ada_Unit is
56865646
Op_NK : Ada_Node_Kind_Type;
56875647

56885648
begin
5689-
56905649
-- Logical operator
56915650

56925651
if Is_Logical_Operator (UIC, N) then
@@ -5733,14 +5692,16 @@ package body Instrument.Ada_Unit is
57335692
else
57345693
Output_Element (N.As_Ada_Node);
57355694

5695+
if Decision_Static or else Do_Not_Instrument then
5696+
return;
5697+
end if;
57365698
if MCDC_Coverage_Enabled then
57375699
UIC.Source_Conditions.Append
57385700
(Source_Condition'
57395701
(LL_SCO => SCOs.SCO_Table.Last,
57405702
Condition => N.As_Expr,
57415703
State => MCDC_State,
5742-
First => Condition_Count = 0,
5743-
Decision_Static => Decision_Static));
5704+
First => Condition_Count = 0));
57445705

57455706
Condition_Count := Condition_Count + 1;
57465707
end if;
@@ -5778,6 +5739,9 @@ package body Instrument.Ada_Unit is
57785739
SFI => UIC.SFI,
57795740
Last => False);
57805741
Hash_Entries.Append ((Start_Sloc (N_SR), SCOs.SCO_Table.Last));
5742+
if Do_Not_Instrument then
5743+
UIC.Non_Instr_LL_SCOs.Include (SCO_Id (SCOs.SCO_Table.Last));
5744+
end if;
57815745
end Output_Element;
57825746

57835747
-------------------
@@ -5858,6 +5822,9 @@ package body Instrument.Ada_Unit is
58585822
SFI => UIC.SFI,
58595823
Last => False,
58605824
Pragma_Aspect_Name => Nam);
5825+
if Do_Not_Instrument then
5826+
UIC.Non_Instr_LL_SCOs.Include (SCO_Id (SCOs.SCO_Table.Last));
5827+
end if;
58615828

58625829
Current_Decision := SCOs.SCO_Table.Last;
58635830

@@ -5896,13 +5863,15 @@ package body Instrument.Ada_Unit is
58965863
-- For this reason, also refrain from instrumenting static
58975864
-- decisions.
58985865

5899-
UIC.Source_Decisions.Append
5900-
(Source_Decision'
5901-
(LL_SCO => Current_Decision,
5902-
Decision => N.As_Expr,
5903-
State => MCDC_State,
5904-
Do_Not_Instrument => Do_Not_Instrument
5905-
or else Is_Static_Expr (N.As_Expr)));
5866+
if not (Do_Not_Instrument
5867+
or else Is_Static_Expr (N.As_Expr))
5868+
then
5869+
UIC.Source_Decisions.Append
5870+
(Source_Decision'
5871+
(LL_SCO => Current_Decision,
5872+
Decision => N.As_Expr,
5873+
State => MCDC_State));
5874+
end if;
59065875
end if;
59075876

59085877
-- For an aspect specification, which will be rewritten into a
@@ -8224,18 +8193,10 @@ package body Instrument.Ada_Unit is
82248193

82258194
if Coverage.Enabled (Decision) or else MCDC_Coverage_Enabled then
82268195
for SD of UIC.Source_Decisions loop
8227-
8228-
-- Mark non-instrumented decisions as such so that they are
8229-
-- properly reported.
8230-
82318196
declare
82328197
HL_SCO : constant SCO_Id := SCO_Map (SD.LL_SCO);
82338198
begin
8234-
if SD.Do_Not_Instrument then
8235-
Set_Decision_SCO_Non_Instr (HL_SCO);
8236-
else
8237-
Insert_Decision_Witness (UIC, SD, Path_Count (HL_SCO));
8238-
end if;
8199+
Insert_Decision_Witness (UIC, SD, Path_Count (HL_SCO));
82398200
end;
82408201
end loop;
82418202

@@ -8249,11 +8210,6 @@ package body Instrument.Ada_Unit is
82498210
-- in a decision with a path count exceeding the limit to avoid
82508211
-- generating overly large traces / run out of memory.
82518212
--
8252-
-- We also do not include witness calls for conditions of
8253-
-- static decision, as this would make the instrumented
8254-
-- expression non-static. Mark the enclosing decision as not
8255-
-- instrumented for MCDC instead.
8256-
--
82578213
-- As we go through each condition, mark their enclosing
82588214
-- decision as not instrumented if their number of paths
82598215
-- exceeds our limit.
@@ -8267,9 +8223,7 @@ package body Instrument.Ada_Unit is
82678223
-- If the number of paths in the decision binary diagram
82688224
-- exceeds the path count limit, we do not instrument it.
82698225

8270-
if Path_Count (Decision) > Get_Path_Count_Limit
8271-
and then not SC.Decision_Static
8272-
then
8226+
if Path_Count (Decision) > Get_Path_Count_Limit then
82738227
Set_Decision_SCO_Non_Instr_For_MCDC (Decision);
82748228
else
82758229
Insert_Condition_Witness

0 commit comments

Comments
 (0)