Skip to content

Commit 32576e0

Browse files
committed
Merge branch 'topic/gnatcheck/forbid_compiler_rules' into 'master'
Unallow compiler based rules in source restricted rule sets Closes #469 See merge request eng/libadalang/langkit-query-language!432
2 parents 00eb903 + 20b293c commit 32576e0

File tree

5 files changed

+35
-0
lines changed

5 files changed

+35
-0
lines changed

lkql_checker/doc/gnatcheck_rm/using_gnatcheck.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,16 @@ only on SPARK code. Those symbols must also refer to an object value formatted l
530530
Ada_2022_In_Ghost_Code
531531
}
532532

533+
Please note that compiler based rules (:ref:`Warnings`, :ref:`Restrictions` and
534+
:ref:`Style_Checks`) cannot be restricted to Ada or SPARK code. Consequently,
535+
the following configuration will raise an error:
536+
537+
::
538+
539+
val spark_rules = @{
540+
Warnings: "a"
541+
}
542+
533543
.. note::
534544

535545
Note that an LKQL rules config file may contain arbitrary computation logic; the only

lkql_checker/src/gnatcheck-rules-rule_table.adb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,16 @@ package body Gnatcheck.Rules.Rule_Table is
12131213
begin
12141214
-- If the rule is a compiler check then get the argument and process it
12151215
if Is_Compiler_Rule (R_Id) then
1216+
-- Ensure the source mode is "BOTH"
1217+
if Source_Mode_String /= "GENERAL" then
1218+
Error_In_Rule_File
1219+
("cannot run compiler base rule """
1220+
& Rule_Name
1221+
& """ only on "
1222+
& Source_Mode_String
1223+
& " code");
1224+
end if;
1225+
12161226
Instance := new Compiler_Instance (Instance_Name /= "");
12171227
Instance.Rule := R_Id;
12181228
Instance.Defined_At := To_Unbounded_String (Output_Rule_File);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
val rules = @{
2+
Goto_Statements
3+
}
4+
5+
val ada_rules = @{
6+
Warnings: "a"
7+
}

testsuite/tests/gnatcheck_errors/invalid_lkql_rules_config/test.out

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,9 @@ gnatcheck: error: Multiple instances with the same name: an_instance (instance_n
8585
gnatcheck: error: no rule to check specified
8686
try "gnatcheck --help" for more information.
8787
>>>program returned status code 2
88+
89+
Compiler base rule in restricted rule set
90+
=========================================
91+
92+
gnatcheck: error: cannot run compiler base rule "warnings" only on ADA code (compiler_rule_in_restricted_source.lkql)
93+
>>>program returned status code 5

testsuite/tests/gnatcheck_errors/invalid_lkql_rules_config/test.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ tests:
2626
lkql_rule_file: extra_param.lkql
2727
- label: Multiple instance with the same name
2828
lkql_rule_file: instance_names.lkql
29+
- label: Compiler base rule in restricted rule set
30+
lkql_rule_file: compiler_rule_in_restricted_source.lkql

0 commit comments

Comments
 (0)