Skip to content

Commit 4b78607

Browse files
committed
Split GNATkp exemptions from others
From now, GNATkp exemptions will have a separate syntax.
1 parent 8318a01 commit 4b78607

File tree

7 files changed

+104
-4
lines changed

7 files changed

+104
-4
lines changed

lkql_checker/doc/gnatcheck_rm/using_gnatcheck.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,24 @@ combined with the ``--kp-version`` and possibly ``--target`` switches,
963963
or with a provided project file) when running GNATkp to ensure the result
964964
soundness.
965965

966+
.. note::
967+
968+
The exemption mechanism is available for GNATkp as well but you have to
969+
change pragmas and comments a bit to avoid conflict with GNATcheck
970+
exemptions. Thus, pragmas annotations' first argument must be ``gnatkp``
971+
instead of ``gnatcheck``:
972+
973+
.. code-block:: ada
974+
975+
pragma Annotate (gnatkp, Exempt_On, "kp_19198", "Justification");
976+
977+
And exemption comments' first word must be ``kp`` instead of ``rule``,
978+
example:
979+
980+
.. code-block:: ada
981+
982+
--## kp off kp_19198 ## Justification
983+
966984
You can check via the GNAT Tracker interface which known problems are
967985
relevant to your version of GNAT and your target before deciding which
968986
known problems may impact you: most known problems are only relevant to a

lkql_checker/src/gnatcheck-diagnoses.adb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,11 +1913,15 @@ package body Gnatcheck.Diagnoses is
19131913
is
19141914
Pragma_Name : constant Text_Type := To_Lower (El.F_Id.Text);
19151915
Pragma_Args : constant LAL.Analysis.Base_Assoc_List := El.F_Args;
1916+
Tool_Name : constant Text_Type :=
1917+
(if Gnatkp_Mode
1918+
then "gnatkp"
1919+
else "gnatcheck");
19161920
begin
19171921
return Pragma_Name in "annotate" | "gnat_annotate"
19181922
and then not Pragma_Args.Is_Null
19191923
and then To_Lower
1920-
(Pragma_Args.List_Child (1).P_Assoc_Expr.Text) = "gnatcheck";
1924+
(Pragma_Args.List_Child (1).P_Assoc_Expr.Text) = Tool_Name;
19211925
end Is_Exemption_Pragma;
19221926

19231927
---------------------------
@@ -2236,7 +2240,11 @@ package body Gnatcheck.Diagnoses is
22362240
return;
22372241
end if;
22382242

2239-
Match (Match_Exempt_Comment, Text, Matches);
2243+
if Gnatkp_Mode then
2244+
Match (Match_Kp_Exempt_Comment, Text, Matches);
2245+
else
2246+
Match (Match_Rule_Exempt_Comment, Text, Matches);
2247+
end if;
22402248

22412249
if Matches (0) = No_Match then
22422250
-- We don't issue a warning here, because, it's possible (however

lkql_checker/src/gnatcheck-diagnoses.ads

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,14 @@ package Gnatcheck.Diagnoses is
4343
Match_Rule_Warning_Param : constant Pattern_Matcher :=
4444
Compile ("(\.?\w)");
4545

46-
Match_Exempt_Comment : constant Pattern_Matcher :=
47-
Compile ("--##\s*rule\s+(line\s+)?(on|off)\s+([^\s]+)[^#]*(?:##(.*))?");
46+
Common_Exempt_Comment_Match : constant String :=
47+
"\s+(line\s+)?(on|off)\s+([^\s]+)[^#]*(?:##(.*))?";
48+
49+
Match_Rule_Exempt_Comment : constant Pattern_Matcher :=
50+
Compile ("--##\s*rule" & Common_Exempt_Comment_Match);
51+
52+
Match_Kp_Exempt_Comment : constant Pattern_Matcher :=
53+
Compile ("--##\s*kp" & Common_Exempt_Comment_Match);
4854

4955
-----------------------
5056
-- Diagnoses storage --
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
project Prj is
2+
for Source_Dirs use ("src");
3+
end Prj;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
procedure Main is
2+
type Int_Arr is array (1 .. 3) of Integer;
3+
4+
X : Int_Arr;
5+
6+
A_1 : Int_Arr := (1, 2, 3) -- FLAG
7+
with Address => X'Address;
8+
9+
pragma Annotate (GnatKP, Exempt_On, "kp_19198", "Because");
10+
A_2 : Int_Arr := (1, 2, 3) -- FLAG
11+
with Address => X'Address;
12+
pragma Annotate (GnatKP, Exempt_Off, "kp_19198");
13+
14+
--## kp off kp_19198 ## Because
15+
A_3 : Int_Arr := (1, 2, 3) -- FLAG
16+
with Address => X'Address;
17+
--## kp on kp_19198
18+
begin
19+
goto lbl; -- FLAG
20+
21+
pragma Annotate (Gnatcheck, Exempt_On, "goto_statements", "Because");
22+
goto lbl; -- FLAG
23+
pragma Annotate (Gnatcheck, Exempt_Off, "goto_statements");
24+
25+
--## rule off goto_statements ## Because
26+
goto lbl; -- FLAG
27+
--## rule on goto_statements
28+
29+
<<lbl>>
30+
end Main;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
GNATcheck mode
2+
==============
3+
4+
main.adb:22:04: goto statement
5+
(Because)
6+
main.adb:26:04: goto statement
7+
(Because)
8+
main.adb:19:04: goto statement
9+
no rule exemption problems detected
10+
no language violations detected
11+
no internal error detected
12+
13+
GNATKP mode
14+
===========
15+
16+
main.adb:10:04: possible occurrence of KP 19198
17+
(Because)
18+
main.adb:15:04: possible occurrence of KP 19198
19+
(Because)
20+
main.adb:6:04: possible occurrence of KP 19198
21+
no rule exemption problems detected
22+
no language violations detected
23+
no internal error detected
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
driver: gnatcheck
2+
project: prj.gpr
3+
format: short
4+
tests:
5+
- label: GNATcheck mode
6+
mode: gnatcheck
7+
rules:
8+
- +Rgoto_statements
9+
- label: GNATKP mode
10+
mode: gnatkp
11+
rules:
12+
- +Rkp_19198

0 commit comments

Comments
 (0)