Skip to content

Commit 12cc246

Browse files
committed
Merge branch 'topic/fix_kp_19142' into 'master'
Fix the KP-19142 detector Closes #506 See merge request eng/libadalang/langkit-query-language!508
2 parents 9eb8747 + 7ac198c commit 12cc246

File tree

3 files changed

+64
-27
lines changed

3 files changed

+64
-27
lines changed

lkql_checker/share/lkql/kp/KP-19142.lkql

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,52 @@ fun is_assigned(id, body) =
88
|" statement in the provided HandledStatements.
99
{
1010
# Get the statements in the subp body and its exception handlers
11-
val stmts = body.f_stmts.children
12-
& concat([eh.f_stmts.children
13-
for eh in body.f_exceptions.children
14-
if eh is ExceptionHandler].to_list);
15-
stdlib.any([s is AssignStmt when s.f_dest.p_referenced_defining_name == id
16-
for s in stmts])
11+
val stmts = body.f_stmts.children & concat([
12+
eh.f_stmts.children
13+
for eh in body.f_exceptions.children
14+
if eh is ExceptionHandler
15+
].to_list);
16+
stdlib.any([
17+
s.f_dest.p_referenced_defining_name() == id
18+
for s in stmts
19+
if s is AssignStmt
20+
])
1721
}
1822

1923
fun is_unconstrained_discriminated(type_decl) =
2024
|" Get if the given BaseTypeDecl is an unconstrained type with a default valued
2125
|" discriminant.
2226
match type_decl
23-
| SubtypeDecl => not type_decl.f_subtype.p_subtype_constraint()
24-
and is_unconstrained_discriminated(type_decl.p_get_type())
25-
| BaseTypeDecl(p_base_type(): not null)
26-
=> not type_decl.f_type_def.f_subtype_indication.p_subtype_constraint()
27-
and is_unconstrained_discriminated(type_decl.p_base_type())
28-
| BaseTypeDecl(p_private_completion(): not null)
29-
=> is_unconstrained_discriminated(type_decl.p_private_completion())
27+
| SubtypeDecl => not type_decl.f_subtype.p_subtype_constraint()
28+
and is_unconstrained_discriminated(type_decl.p_get_type())
29+
| BaseTypeDecl(
30+
p_base_type(): not null
31+
) => not type_decl.f_type_def.f_subtype_indication.p_subtype_constraint()
32+
and is_unconstrained_discriminated(type_decl.p_base_type())
33+
| BaseTypeDecl(
34+
p_private_completion(): not null
35+
) => is_unconstrained_discriminated(type_decl.p_private_completion())
3036
# TODO: Remove the 'p_discriminants_list' parameter when langkit#776 will be resolved
31-
| BaseTypeDecl => stdlib.any([d.f_default_expr != null
32-
for d in type_decl.p_discriminants_list(type_decl.p_root_type())])
33-
| * => false
37+
| BaseTypeDecl => stdlib.any([
38+
d.f_default_expr != null
39+
for d in type_decl.p_discriminants_list(type_decl.p_root_type())
40+
])
41+
| * => false
3442

3543
@check(help="possible occurrence of KP 19142",
3644
message="possible occurrence of KP 19142")
3745
fun kp_19142(node) =
3846
node is SubpBody
3947
# Check that the subprogram is overriding
4048
when node.p_root_subp_declarations()
41-
# Check that the subprogram hasn't been declared earlier, otherwise the KP
42-
# won't happen.
43-
and not node.p_decl_part()
44-
and stdlib.any([stdlib.any([is_assigned(id, node.f_stmts)
45-
for id in p.f_ids.children])
46-
for p in node.f_subp_spec.p_params()
47-
if is_unconstrained_discriminated(p.p_formal_type())
48-
and p.f_mode is (ModeOut | ModeInOut)])
49+
# Check that the subprogram hasn't been declared earlier, otherwise the KP
50+
# won't happen.
51+
and not node.p_decl_part()
52+
and stdlib.any([
53+
stdlib.any([
54+
is_assigned(id, node.f_stmts) for id in p.f_ids.children
55+
])
56+
for p in node.f_subp_spec.p_params()
57+
if is_unconstrained_discriminated(p.p_formal_type())
58+
and p.f_mode is (ModeOut | ModeInOut)
59+
])
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
main.adb:17:19: rule violation: possible occurrence of KP 19142
2+
17 | procedure Test_Implicit (I : Implicit; Mut : out Mutable) is -- FLAG
3+
| ^^^^^^^^^^^^^
4+
5+
main.adb:29:30: rule violation: possible occurrence of KP 19142
6+
29 | overriding procedure Test_Explicit (I : Explicit; Mut : out Mutable) is -- FLAG
7+
| ^^^^^^^^^^^^^
8+
9+
main.adb:44:19: rule violation: possible occurrence of KP 19142
10+
44 | procedure Test_Subtype (I : Sub; Mut : out Sub_Mutable) is -- FLAG
11+
| ^^^^^^^^^^^^
12+
13+
main.adb:51:19: rule violation: possible occurrence of KP 19142
14+
51 | procedure Test_Derived (I : Derived; Mut : out Derived_Mutable) is -- FLAG
15+
| ^^^^^^^^^^^^
16+
17+
main.adb:58:19: rule violation: possible occurrence of KP 19142
18+
58 | procedure Test_Private (I : Priv; Mut: out Private_Mutable) is -- FLAG
19+
| ^^^^^^^^^^^^
20+
21+
main.adb:65:19: rule violation: possible occurrence of KP 19142
22+
65 | procedure Test_Read_And_Write (I : Read_And_Write; Mut : in out Mutable) is -- FLAG
23+
| ^^^^^^^^^^^^^^^^^^^
24+
25+
main.adb:72:19: rule violation: possible occurrence of KP 19142
26+
72 | procedure Test_Exc_Hand (I : Exc_Hand; Mut : out Mutable) is -- FLAG
27+
| ^^^^^^^^^^^^^
28+
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
driver: checker
2-
rule_name: KP_19142
2+
rule_name: kp_19142
33
project: prj.gpr
4-
control:
5-
- ["XFAIL", "True", "KP detector is invalid (eng/libadalang/langkit-query-language#506)"]

0 commit comments

Comments
 (0)