Skip to content

Commit f705c0b

Browse files
committed
Merge branch 'topic/kp_19423' into 'master'
Implement KP detector for 19423 Closes #331 See merge request eng/libadalang/langkit-query-language!290
2 parents 58f571e + d921608 commit f705c0b

File tree

6 files changed

+63
-0
lines changed

6 files changed

+63
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@check(help="possible occurrence of KP 19423",
2+
message="possible occurrence of KP 19423",
3+
impact="22.*,23.*,24.*")
4+
fun kp_19423(node) =
5+
|" Flag all "for ... in" loops which iterate over expressions of the
6+
|" form "F'Range", where F is a function call.
7+
node is ForLoopStmt(f_spec: spec@ForLoopSpec(f_loop_type: IterTypeIn))
8+
when spec.f_iter_expr is ref@AttributeRef
9+
when ref.f_attribute?.p_canonical_text() == "range"
10+
and ref.f_prefix.p_is_call()
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
procedure Main is
2+
type Int_Array is array (Positive range <>) of Integer;
3+
A : Int_Array (1 .. 3) := (1, 2, 3);
4+
function F return Int_Array is (A);
5+
function G (X : Integer) return Int_Array is (A);
6+
begin
7+
for I in F'Range loop -- FLAG
8+
null;
9+
end loop;
10+
11+
for I of F loop -- NOFLAG
12+
null;
13+
end loop;
14+
15+
for I in G (0)'Range loop -- FLAG
16+
null;
17+
end loop;
18+
19+
for I in A'Range loop -- NOFLAG
20+
null;
21+
end loop;
22+
end Main;
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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
main.adb:7:4: rule violation: possible occurrence of KP 19423
2+
7 | for I in F'Range loop -- FLAG
3+
| ____^
4+
||
5+
|| ~~~ 1 other lines ~~~
6+
||
7+
9 || end loop;
8+
||____________^
9+
10+
main.adb:15:4: rule violation: possible occurrence of KP 19423
11+
15 | for I in G (0)'Range loop -- FLAG
12+
| ____^
13+
||
14+
|| ~~~ 1 other lines ~~~
15+
||
16+
17 || end loop;
17+
||____________^
18+
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_19423
3+
project: prj.gpr

testsuite/tests/gnatcheck/xml_help/test.out

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ testsuite_driver: No output file generated by gnatcheck
156156
<check switch="+Rkp_19237" label="possible occurrence of KP 19237"/>
157157
<check switch="+Rkp_19312" label="possible occurrence of KP 19312"/>
158158
<check switch="+Rkp_19341" label="possible occurrence of KP 19341"/>
159+
<check switch="+Rkp_19423" label="possible occurrence of KP 19423"/>
159160
<check switch="+Rkp_19447" label="possible occurrence of KP 19447"/>
160161
<check switch="+Rkp_ob03_009" label="possible occurrence of KP OB03-009"/>
161162
<check switch="+Rkp_p226_024" label="possible occurrence of KP P226-024 - global analysis required"/>
@@ -304,6 +305,7 @@ testsuite_driver: No output file generated by gnatcheck
304305
<check switch="+Rkp_19237" label="possible occurrence of KP 19237"/>
305306
<check switch="+Rkp_19312" label="possible occurrence of KP 19312"/>
306307
<check switch="+Rkp_19341" label="possible occurrence of KP 19341"/>
308+
<check switch="+Rkp_19423" label="possible occurrence of KP 19423"/>
307309
<check switch="+Rkp_19447" label="possible occurrence of KP 19447"/>
308310
<check switch="+Rkp_ob03_009" label="possible occurrence of KP OB03-009"/>
309311
<check switch="+Rkp_p226_024" label="possible occurrence of KP P226-024 - global analysis required"/>
@@ -464,6 +466,7 @@ testsuite_driver: No output file generated by gnatcheck
464466
<check switch="+Rkp_19237" label="possible occurrence of KP 19237"/>
465467
<check switch="+Rkp_19312" label="possible occurrence of KP 19312"/>
466468
<check switch="+Rkp_19341" label="possible occurrence of KP 19341"/>
469+
<check switch="+Rkp_19423" label="possible occurrence of KP 19423"/>
467470
<check switch="+Rkp_19447" label="possible occurrence of KP 19447"/>
468471
<check switch="+Rkp_ob03_009" label="possible occurrence of KP OB03-009"/>
469472
<check switch="+Rkp_p226_024" label="possible occurrence of KP P226-024 - global analysis required"/>
@@ -646,6 +649,7 @@ testsuite_driver: No output file generated by gnatcheck
646649
<check switch="+Rkp_19237" label="possible occurrence of KP 19237"/>
647650
<check switch="+Rkp_19312" label="possible occurrence of KP 19312"/>
648651
<check switch="+Rkp_19341" label="possible occurrence of KP 19341"/>
652+
<check switch="+Rkp_19423" label="possible occurrence of KP 19423"/>
649653
<check switch="+Rkp_19447" label="possible occurrence of KP 19447"/>
650654
<check switch="+Rkp_ob03_009" label="possible occurrence of KP OB03-009"/>
651655
<check switch="+Rkp_p226_024" label="possible occurrence of KP P226-024 - global analysis required"/>
@@ -837,6 +841,7 @@ testsuite_driver: No output file generated by gnatcheck
837841
<check switch="+Rkp_19237" label="possible occurrence of KP 19237"/>
838842
<check switch="+Rkp_19312" label="possible occurrence of KP 19312"/>
839843
<check switch="+Rkp_19341" label="possible occurrence of KP 19341"/>
844+
<check switch="+Rkp_19423" label="possible occurrence of KP 19423"/>
840845
<check switch="+Rkp_19447" label="possible occurrence of KP 19447"/>
841846
<check switch="+Rkp_ob03_009" label="possible occurrence of KP OB03-009"/>
842847
<check switch="+Rkp_p226_024" label="possible occurrence of KP P226-024 - global analysis required"/>
@@ -1073,6 +1078,7 @@ testsuite_driver: No output file generated by gnatcheck
10731078
<check switch="+Rkp_19237" label="possible occurrence of KP 19237"/>
10741079
<check switch="+Rkp_19312" label="possible occurrence of KP 19312"/>
10751080
<check switch="+Rkp_19341" label="possible occurrence of KP 19341"/>
1081+
<check switch="+Rkp_19423" label="possible occurrence of KP 19423"/>
10761082
<check switch="+Rkp_19447" label="possible occurrence of KP 19447"/>
10771083
<check switch="+Rkp_ob03_009" label="possible occurrence of KP OB03-009"/>
10781084
<check switch="+Rkp_p226_024" label="possible occurrence of KP P226-024 - global analysis required"/>
@@ -1429,6 +1435,7 @@ testsuite_driver: No output file generated by gnatcheck
14291435
<check switch="+Rkp_19237" label="possible occurrence of KP 19237"/>
14301436
<check switch="+Rkp_19312" label="possible occurrence of KP 19312"/>
14311437
<check switch="+Rkp_19341" label="possible occurrence of KP 19341"/>
1438+
<check switch="+Rkp_19423" label="possible occurrence of KP 19423"/>
14321439
<check switch="+Rkp_19447" label="possible occurrence of KP 19447"/>
14331440
<check switch="+Rkp_ob03_009" label="possible occurrence of KP OB03-009"/>
14341441
<check switch="+Rkp_p226_024" label="possible occurrence of KP P226-024 - global analysis required"/>
@@ -1796,6 +1803,7 @@ testsuite_driver: No output file generated by gnatcheck
17961803
<check switch="+Rkp_19237" label="possible occurrence of KP 19237"/>
17971804
<check switch="+Rkp_19312" label="possible occurrence of KP 19312"/>
17981805
<check switch="+Rkp_19341" label="possible occurrence of KP 19341"/>
1806+
<check switch="+Rkp_19423" label="possible occurrence of KP 19423"/>
17991807
<check switch="+Rkp_19447" label="possible occurrence of KP 19447"/>
18001808
<check switch="+Rkp_ob03_009" label="possible occurrence of KP OB03-009"/>
18011809
<check switch="+Rkp_p226_024" label="possible occurrence of KP P226-024 - global analysis required"/>

0 commit comments

Comments
 (0)