Skip to content

Commit

Permalink
Merge branch 'topic/257' into 'master'
Browse files Browse the repository at this point in the history
Add KP detector for eng/toolchain/gnat#693.

Closes #257

See merge request eng/libadalang/langkit-query-language!210
  • Loading branch information
Roldak committed Apr 25, 2024
2 parents e3872d8 + ccd9e88 commit 7520bb7
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lkql_checker/share/lkql/kp/KP-19038.lkql
@@ -0,0 +1,8 @@
@check(help="possible occurrence of KP 19038",
message="possible occurrence of KP 19038",
impact="24.1")
fun kp_19038(node) =
|" Detect all occurrences of aspect "Exclusive_Functions".
node is AspectAssoc(
f_id: Name(p_name_is("exclusive_functions"): true)
)
2 changes: 2 additions & 0 deletions testsuite/tests/checks/KP-19038/prj.gpr
@@ -0,0 +1,2 @@
project Prj is
end Prj;
60 changes: 60 additions & 0 deletions testsuite/tests/checks/KP-19038/test.adb
@@ -0,0 +1,60 @@
with Ada.Text_IO;

procedure Excl1 is
protected type PT with Exclusive_Functions is -- FLAG
function Unlock return Boolean;
procedure Unlock;
entry E;
end PT;

Locked : Boolean := True;

protected body PT is
function Unlock return Boolean is
Previous : constant Boolean := Locked;
begin
Locked := False;
return Previous;
end;

procedure Unlock is
begin
Locked := False;
end;

entry E when not Locked is
begin
Locked := True;
end;
end;

PO : PT;

task T;

task body T is
Unused : Boolean;
begin
delay 1.0;
PO.Unlock;
delay 1.0;
Unused := PO.Unlock;
end;

begin
select
PO.E;
Ada.Text_IO.Put_Line ("Entry call succeeded");
or
delay 2.0;
Ada.Text_IO.Put_Line ("Entry call timed out");
end select;

select
PO.E;
Ada.Text_IO.Put_Line ("Entry call succeeded");
or
delay 2.0;
Ada.Text_IO.Put_Line ("Entry call timed out");
end select;
end;
4 changes: 4 additions & 0 deletions testsuite/tests/checks/KP-19038/test.out
@@ -0,0 +1,4 @@
test.adb:4:27: rule violation: possible occurrence of KP 19038
4 | protected type PT with Exclusive_Functions is -- FLAG
| ^^^^^^^^^^^^^^^^^^^

3 changes: 3 additions & 0 deletions testsuite/tests/checks/KP-19038/test.yaml
@@ -0,0 +1,3 @@
driver: checker
rule_name: KP_19038
project: prj.gpr

0 comments on commit 7520bb7

Please sign in to comment.