Skip to content

Commit 176ea33

Browse files
committed
Merge branch 'topic/507' into 'master'
Add detector for KP-19824 Closes #507 See merge request eng/libadalang/langkit-query-language!491
2 parents 23bc091 + 75373b2 commit 176ea33

File tree

13 files changed

+121
-6
lines changed

13 files changed

+121
-6
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import kp_v404_040_internal
2+
3+
@check(help="possible occurrence of KP 19824",
4+
message="possible occurrence of KP 19824")
5+
fun kp_19824(node) =
6+
|" Flag 'Valid attribute applied to a floating-point component of a
7+
|" composite type subject to a Scalar_Storage_Order aspect/clause.
8+
kp_v404_040_internal.check(node)
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
# Flag 'Valid applied to floating-point components of composite types that
22
# specify a non default Scalar_Storage_Order aspect.
33

4-
import stdlib
4+
import kp_v404_040_internal
55

66
@check(message="possible occurrence of KP V404-040")
77
fun kp_v404_040(node) =
8-
node is AttributeRef
9-
when node.f_attribute.p_name_is("Valid")
10-
and node.f_prefix.p_expression_type().p_is_float_type()
11-
and node.f_prefix.p_referenced_decl() is c@ComponentDecl
12-
when stdlib.has_non_default_sso(c.p_semantic_parent())
8+
kp_v404_040_internal.check(node)

lkql_checker/share/lkql/kp/kp.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"kp_19747": "24.1,24.2",
2626
"kp_19749": "24.*,25.*",
2727
"kp_19753": "21.*,22.*,23.*,24.1,24.2,25.1",
28+
"kp_19824": "25.*",
2829
"kp_ob03_009": "19.*",
2930
"kp_p226_024": "7.1.*,7.2.*,7.3.*,7.4.1,7.4.2,7.4.3",
3031
"kp_q309_014": "7.1.*,7.2.*,7.3.*,7.4.*,17.*",
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import stdlib
2+
3+
fun check(node) =
4+
|" Detect 'Valid attribute applied to a floating-point component of a
5+
|" composite type subject to a Scalar_Storage_Order aspect/clause.
6+
node is AttributeRef
7+
when node.f_attribute.p_name_is("Valid")
8+
and node.f_prefix.p_expression_type().p_is_float_type()
9+
and node.f_prefix.p_referenced_decl() is decl@BasicDecl
10+
when match decl
11+
# Only records and arrays can have the Scalar_Storage_Order aspect
12+
| cd@ComponentDecl => stdlib.has_non_default_sso(cd.p_semantic_parent())
13+
| od@ObjectDecl => {
14+
val td = od.p_type_expression().p_designated_type_decl();
15+
td.p_is_array_type() and stdlib.has_non_default_sso(td)
16+
}
17+
| * => false

lkql_checker/share/lkql/stdlib.lkql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ fun is_composite_type(decl) =
446446
val v = decl.p_full_view();
447447
v.p_is_array_type() or
448448
v.p_is_record_type() or
449+
v.p_is_interface_type() or
449450
v.p_root_type() is (TaskTypeDecl | ProtectedTypeDecl)
450451
}
451452

testsuite/tests/checks/KP-19824/p.adb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
with System;
2+
3+
procedure P is
4+
type Angle_Type is new Float range 0.0 .. 359.99;
5+
-- Derived floating point type
6+
7+
-- Record type with floating point elements.
8+
type My_Record_Type is record
9+
Az : Angle_Type;
10+
El : Angle_Type;
11+
end record;
12+
13+
-- Big endian byte order
14+
for My_Record_Type'Bit_Order use System.High_Order_First;
15+
for My_Record_Type'Scalar_Storage_Order use System.High_Order_First;
16+
17+
type My_Record_Type2 is record
18+
Az : Angle_Type;
19+
El : Angle_Type;
20+
end record;
21+
22+
My_Record : My_Record_Type := (1.1, 2.2);
23+
My_Record2 : My_Record_Type2 := (1.1, 2.2);
24+
25+
Is_Valid : Boolean := My_Record.Az'Valid; -- FLAG
26+
27+
begin
28+
Is_Valid := My_Record2.Az'Valid; -- NOFLAG
29+
end P;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
with System;
2+
3+
procedure P2 is
4+
type Angle_Type is new Float range 0.0 .. 359.99;
5+
-- Derived floating point type
6+
7+
-- Array type with floating point elements.
8+
type My_Array_Type is array (1 .. 2) of Angle_Type;
9+
10+
-- Big endian byte order
11+
for My_Array_Type'Scalar_Storage_Order use System.High_Order_First;
12+
13+
type My_Array_Type2 is array (1 .. 2) of Angle_Type;
14+
15+
My_Array : My_Array_Type := (1.1, 2.2);
16+
My_Array2 : My_Array_Type2 := (1.1, 2.2);
17+
18+
Is_Valid : Boolean := My_Array (1)'Valid; -- FLAG
19+
20+
begin
21+
Is_Valid := My_Array2 (1)'Valid; -- NOFLAG
22+
end P2;
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
p.adb:25:26: rule violation: possible occurrence of KP 19824
2+
25 | Is_Valid : Boolean := My_Record.Az'Valid; -- FLAG
3+
| ^^^^^^^^^^^^^^^^^^
4+
5+
p2.adb:18:26: rule violation: possible occurrence of KP 19824
6+
18 | Is_Valid : Boolean := My_Array (1)'Valid; -- 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_19824
3+
project: 'prj.gpr'

0 commit comments

Comments
 (0)