File tree Expand file tree Collapse file tree 4 files changed +45
-6
lines changed
lkql_checker/share/lkql/kp
testsuite/tests/checks/KP-V404-040 Expand file tree Collapse file tree 4 files changed +45
-6
lines changed Original file line number Diff line number Diff line change 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")
77fun 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)
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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 ;
Original file line number Diff line number Diff line change @@ -2,3 +2,7 @@ p.adb:25:26: rule violation: possible occurrence of KP V404-040
2225 | 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+
You can’t perform that action at this time.
0 commit comments