Skip to content

Commit

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

Closes #255

See merge request eng/libadalang/langkit-query-language!205
  • Loading branch information
Roldak committed Apr 25, 2024
2 parents 7520bb7 + b496117 commit 4e91615
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lkql_checker/share/lkql/kp/KP-19159.lkql
@@ -0,0 +1,16 @@
import stdlib

@check(help="possible occurrence of KP 19159",
message="possible occurrence of KP 19159",
impact="23.*,24.*")
fun kp_19159(node) =
|" Look for a value conversion between array types directly
|" passed as an actual parameter in a call to a subprogram.
node is CallExpr(p_is_call(): true) when stdlib.any([
p.actual is CallExpr(
p_kind(): "type_conversion",
p_expression_type(): BaseTypeDecl(p_is_array_type(): true)
)
for p in node.p_call_params()
])

2 changes: 2 additions & 0 deletions testsuite/tests/checks/KP-19159/prj.gpr
@@ -0,0 +1,2 @@
project Prj is
end Prj;
30 changes: 30 additions & 0 deletions testsuite/tests/checks/KP-19159/test.adb
@@ -0,0 +1,30 @@
procedure Test is

type Arr1 is array (1 .. 32) of Integer;

type Arr2 is array (1 .. 32) of Integer;

type Int is range 1 .. 100;

procedure Foo (A : Arr2) is
begin
if A (16) /= 42 then
raise Program_Error;
end if;
end Foo;

procedure Bar (X : Integer) is
begin
null;
end Bar;

A : Arr1;
B : Int := 10;
C : Arr2;

begin
A (16) := 42;
Foo (Arr2 (A)); -- FLAG
Bar (Integer (B)); -- NOFLAG
C := Arr2 (A); -- NOFLAG
end Test;
4 changes: 4 additions & 0 deletions testsuite/tests/checks/KP-19159/test.out
@@ -0,0 +1,4 @@
test.adb:27:3: rule violation: possible occurrence of KP 19159
27 | Foo (Arr2 (A)); -- FLAG
| ^^^^^^^^^^^^^^

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

0 comments on commit 4e91615

Please sign in to comment.