Skip to content

Commit 7074382

Browse files
committed
Merge branch 'mr/thevenoux/langkit-query-language#552' into 'master'
Add detector for KP-20112 Closes #552 See merge request eng/libadalang/langkit-query-language!586
2 parents 178f7e2 + be290bd commit 7074382

File tree

6 files changed

+64
-0
lines changed

6 files changed

+64
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import stdlib
2+
3+
fun has_convention(node, convention) =
4+
|" Return whether ``node`` has the Convention aspect sets to ``convention``.
5+
{
6+
val aspect = node.p_get_aspect("Convention");
7+
8+
aspect.exists
9+
and aspect.value.text.to_lower_case == convention.to_lower_case
10+
}
11+
12+
@check(help="possible occurrence of KP 20112",
13+
message="possible occurrence of KP 20112")
14+
fun kp_20112(node) =
15+
|" Flag a convention-C anonymous access-to-subprogram types with a profile
16+
|" that includes a parameter of a type for which a convention of
17+
|" C_Pass_By_Copy is specified.
18+
node is AnonymousTypeDecl
19+
when node.f_type_def is as@AccessToSubpDef
20+
when stdlib.any([
21+
p is BasicDecl and has_convention(p, "C") for p in node.parents()
22+
]) and stdlib.any([
23+
p.f_type_expr.p_designated_type_decl() is td@BaseTypeDecl
24+
when has_convention(td, "C_Pass_By_Copy")
25+
for p in as.f_subp_spec.f_subp_params.f_params.children
26+
])
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
project Prj is
2+
end Prj;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package Test is
2+
type T is record
3+
I : Integer;
4+
end record;
5+
6+
type S is record
7+
V : Integer;
8+
end record with Convention => C_Pass_By_Copy;
9+
10+
type R is record
11+
Callback : access procedure (Val : S) with Convention => C; -- FLAG
12+
end record with Convention => C;
13+
14+
function Get return access procedure (Val : S); -- NOFLAG
15+
16+
type Acc is access procedure (Val : S) with Convention => C; -- NOFLAG
17+
18+
function Foo return access procedure (Val : T) with Convention => C; -- NOGLAG
19+
20+
function Bar return access procedure (Val : S); -- NOGLAG
21+
22+
function Baz return access procedure (Val : T; Vbl : S; Vcl : R) with Convention => C; -- FLAG
23+
end Test;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
test.ads:11:18: rule violation: possible occurrence of KP 20112
2+
11 | Callback : access procedure (Val : S) with Convention => C; -- FLAG
3+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
4+
5+
test.ads:22:24: rule violation: possible occurrence of KP 20112
6+
22 | function Baz return access procedure (Val : T; Vbl : S; Vcl : R) with Convention => C; -- FLAG
7+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
driver: checker
2+
rule_name: kp_20112
3+
project: prj.gpr

testsuite/tests/gnatcheck/xml_help/test.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ testsuite_driver: No output file generated by gnatcheck
9898
<check switch="+Rkp_19997" label="possible occurrence of KP 19997"/>
9999
<check switch="+Rkp_20023" label="possible occurrence of KP 20023"/>
100100
<check switch="+Rkp_20089" label="possible occurrence of KP 20089"/>
101+
<check switch="+Rkp_20112" label="possible occurrence of KP 20112"/>
101102
<check switch="+Rkp_20113" label="possible occurrence of KP 20113"/>
102103
<check switch="+Rkp_20186" label="possible occurrence of KP 20186"/>
103104
<check switch="+Rkp_ob03_009" label="possible occurrence of KP OB03-009"/>
@@ -623,6 +624,7 @@ testsuite_driver: No output file generated by gnatcheck
623624
<check switch="+Rkp_19997" label="possible occurrence of KP 19997"/>
624625
<check switch="+Rkp_20023" label="possible occurrence of KP 20023"/>
625626
<check switch="+Rkp_20089" label="possible occurrence of KP 20089"/>
627+
<check switch="+Rkp_20112" label="possible occurrence of KP 20112"/>
626628
<check switch="+Rkp_20113" label="possible occurrence of KP 20113"/>
627629
<check switch="+Rkp_20186" label="possible occurrence of KP 20186"/>
628630
<check switch="+Rkp_ob03_009" label="possible occurrence of KP OB03-009"/>

0 commit comments

Comments
 (0)