Skip to content

Commit 7841541

Browse files
committed
Merge branch 'topic/524' into 'master'
Add detector for KP-19997 Closes #524 See merge request eng/libadalang/langkit-query-language!531
2 parents 984e4c1 + 7f2a875 commit 7841541

File tree

6 files changed

+60
-0
lines changed

6 files changed

+60
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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()))
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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
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+
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_19997
3+
project: 'prj.gpr'

testsuite/tests/gnatcheck/xml_help/test.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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"/>

0 commit comments

Comments
 (0)