diff --git a/lkql_checker/share/lkql/kp/KP-19159.lkql b/lkql_checker/share/lkql/kp/KP-19159.lkql new file mode 100644 index 000000000..dd7481826 --- /dev/null +++ b/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() + ]) + diff --git a/testsuite/tests/checks/KP-19159/prj.gpr b/testsuite/tests/checks/KP-19159/prj.gpr new file mode 100644 index 000000000..3abfff4af --- /dev/null +++ b/testsuite/tests/checks/KP-19159/prj.gpr @@ -0,0 +1,2 @@ +project Prj is +end Prj; diff --git a/testsuite/tests/checks/KP-19159/test.adb b/testsuite/tests/checks/KP-19159/test.adb new file mode 100644 index 000000000..32cb407d4 --- /dev/null +++ b/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; diff --git a/testsuite/tests/checks/KP-19159/test.out b/testsuite/tests/checks/KP-19159/test.out new file mode 100644 index 000000000..11909429b --- /dev/null +++ b/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 + | ^^^^^^^^^^^^^^ + diff --git a/testsuite/tests/checks/KP-19159/test.yaml b/testsuite/tests/checks/KP-19159/test.yaml new file mode 100644 index 000000000..97b84130f --- /dev/null +++ b/testsuite/tests/checks/KP-19159/test.yaml @@ -0,0 +1,3 @@ +driver: checker +rule_name: KP_19159 +project: prj.gpr