File tree Expand file tree Collapse file tree 6 files changed +60
-0
lines changed
lkql_checker/share/lkql/kp Expand file tree Collapse file tree 6 files changed +60
-0
lines changed Original file line number Diff line number Diff line change 1+ # Flag calls to Unchecked_Conversion where arguments have different
2+ # Scalar_Storage_Order.
3+
4+ import stdlib
5+
6+ fun sso(decl) =
7+ |" Return the ``Scalar_Storage_Order`` associated to ``decl`` in the form
8+ |" of a fully qualified name.
9+ {
10+ val aspect = decl.p_get_aspect("Scalar_Storage_Order");
11+
12+ (match aspect.value
13+ | i@Identifier => i
14+ | * => stdlib.default_bit_order()
15+ ).p_referenced_decl().p_canonical_fully_qualified_name()
16+ }
17+
18+ @check(help="possible occurrence of KP 19997",
19+ message="possible occurrence of KP 19997 if compiled with optimization")
20+ fun kp_19997(node) =
21+ node is gsi@GenericSubpInstantiation
22+ when gsi.f_kind is SubpKindFunction
23+ and gsi.p_designated_generic_decl().p_get_uninstantiated_node()
24+ .p_canonical_fully_qualified_name() == "ada.unchecked_conversion"
25+ and (sso(gsi.f_params[1].f_r_expr.p_referenced_decl()) !=
26+ sso(gsi.f_params[2].f_r_expr.p_referenced_decl()))
Original file line number Diff line number Diff line change 1+ project Prj is
2+ end Prj;
Original file line number Diff line number Diff line change 1+ with Ada.Unchecked_Conversion ;
2+
3+ with Interfaces ; use Interfaces;
4+ with System ; use System;
5+
6+ procedure Test is
7+ type Bytes is array (0 .. 3 ) of Unsigned_8
8+ with Scalar_Storage_Order => Low_Order_First;
9+
10+ type Bytes_BE is new Bytes
11+ with Scalar_Storage_Order => High_Order_First;
12+
13+ type Bytes_LE is new Bytes
14+ with Scalar_Storage_Order => Low_Order_First;
15+
16+ function To_Bytes is new Ada.Unchecked_Conversion (Unsigned_32, Bytes); -- NOFLAG
17+
18+ function To_Bytes_BE is new Ada.Unchecked_Conversion (Unsigned_32, Bytes_BE); -- FLAG
19+
20+ function To_Bytes_LE is new Ada.Unchecked_Conversion (Unsigned_32, Bytes_LE); -- NOFLAG
21+ begin
22+ null ;
23+ end ;
Original file line number Diff line number Diff line change 1+ test.adb:18:13: rule violation: possible occurrence of KP 19997 if compiled with optimization
2+ 18 | function To_Bytes_BE is new Ada.Unchecked_Conversion (Unsigned_32, Bytes_BE); -- FLAG
3+ | ^^^^^^^^^^^
4+
Original file line number Diff line number Diff line change 1+ driver : ' checker'
2+ rule_name : KP_19997
3+ project : ' prj.gpr'
Original file line number Diff line number Diff line change @@ -95,6 +95,7 @@ testsuite_driver: No output file generated by gnatcheck
9595 <check switch="+Rkp_19853" label="possible occurrence of KP 19853"/>
9696 <check switch="+Rkp_19901" label="possible occurrence of KP 19901"/>
9797 <check switch="+Rkp_19915" label="occurrence of KP 19915"/>
98+ <check switch="+Rkp_19997" label="possible occurrence of KP 19997"/>
9899 <check switch="+Rkp_20023" label="occurrence of KP 20023"/>
99100 <check switch="+Rkp_ob03_009" label="possible occurrence of KP OB03-009"/>
100101 <check switch="+Rkp_p226_024" label="possible occurrence of KP P226-024 - global analysis required"/>
@@ -616,6 +617,7 @@ testsuite_driver: No output file generated by gnatcheck
616617 <check switch="+Rkp_19853" label="possible occurrence of KP 19853"/>
617618 <check switch="+Rkp_19901" label="possible occurrence of KP 19901"/>
618619 <check switch="+Rkp_19915" label="occurrence of KP 19915"/>
620+ <check switch="+Rkp_19997" label="possible occurrence of KP 19997"/>
619621 <check switch="+Rkp_20023" label="occurrence of KP 20023"/>
620622 <check switch="+Rkp_ob03_009" label="possible occurrence of KP OB03-009"/>
621623 <check switch="+Rkp_p226_024" label="possible occurrence of KP P226-024 - global analysis required"/>
You can’t perform that action at this time.
0 commit comments