Skip to content

Commit b50037a

Browse files
committed
Fix KP-V404-040
KP-V404-040 should check for records and arrays but the latter was missing. Also, this change moves KP-V404-040's code to a new file, without `-` in its name. We'll need it to import KP-V404-040's detection function into KP-19824 since the two KPs are identical.
1 parent ed025dd commit b50037a

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed
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)
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
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;

testsuite/tests/checks/KP-V404-040/test.out

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@ p.adb:25:26: rule violation: possible occurrence of KP V404-040
22
25 | Is_Valid : Boolean := My_Record.Az'Valid; -- FLAG
33
| ^^^^^^^^^^^^^^^^^^
44

5+
p2.adb:18:26: rule violation: possible occurrence of KP V404-040
6+
18 | Is_Valid : Boolean := My_Array (1)'Valid; -- FLAG
7+
| ^^^^^^^^^^^^^^^^^^
8+

0 commit comments

Comments
 (0)