Skip to content

Commit aa522e3

Browse files
authored
Merge pull request #1784 from goblint/semgrep-batenum
Add semgrep rule for `BatEnum`
2 parents f20fcd2 + ee9039b commit aa522e3

File tree

16 files changed

+112
-91
lines changed

16 files changed

+112
-91
lines changed

.semgrep/batenum.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
rules:
2+
- id: batenum-module
3+
pattern-either:
4+
- pattern: BatEnum.$F
5+
- pattern: Enum.$F
6+
message: use Seq.$F instead
7+
languages: [ocaml]
8+
severity: WARNING
9+
10+
- id: batenum-of_enum
11+
patterns:
12+
- pattern: $M.of_enum
13+
- metavariable-pattern:
14+
metavariable: $M
15+
pattern-regex: ^[A-Z].*
16+
message: use $M.of_seq instead
17+
languages: [ocaml]
18+
severity: WARNING
19+
20+
- id: batenum-enum
21+
patterns:
22+
- pattern: $M.enum
23+
- metavariable-pattern:
24+
metavariable: $M
25+
pattern-regex: ^[A-Z].*
26+
message: use $M.to_seq instead
27+
languages: [ocaml]
28+
severity: WARNING

src/analyses/apron/relationPriv.apron.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,8 @@ struct
727727
let rel = keep_only_protected_globals ask m' (get_m_with_mutex_inits ask getg m') in (* Could be more precise if mutex_inits invariant is added by disjunction instead of joining abstract values. *)
728728
let inv =
729729
RD.invariant rel
730-
|> List.enum
731-
|> Enum.filter_map (fun (lincons1: Apron.Lincons1.t) ->
730+
|> List.to_seq
731+
|> Seq.filter_map (fun (lincons1: Apron.Lincons1.t) ->
732732
(* filter one-vars and exact *)
733733
(* RD.invariant simplifies two octagon SUPEQ constraints to one EQ, so exact works *)
734734
if (one_var || GobApron.Lincons1.num_vars lincons1 >= 2) && (exact || Apron.Lincons1.get_typ lincons1 <> EQ) then
@@ -737,7 +737,7 @@ struct
737737
else
738738
None
739739
)
740-
|> Enum.fold (fun acc x -> Invariant.(acc && of_exp x)) Invariant.none
740+
|> Seq.fold_left (fun acc x -> Invariant.(acc && of_exp x)) Invariant.none
741741
in
742742
if atomic then
743743
inv

src/analyses/assert.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct
2727
let warn warn_fn ?annot msg = if check then
2828
if get_bool "dbg.regression" then ( (* This only prints unexpected results (with the difference) as indicated by the comment behind the assert (same as used by the regression test script). *)
2929
let loc = !M.current_loc in
30-
let line = List.at (List.of_enum @@ File.lines_of loc.file) (loc.line-1) in
30+
let line = List.at (List.of_enum @@ File.lines_of loc.file) (loc.line-1) in (* nosemgrep: batenum-of_enum *)
3131
let open Str in
3232
let expected = if string_match (regexp ".+//.*\\(FAIL\\|UNKNOWN\\).*") line 0 then Some (matched_group 1 line) else None in
3333
if expected <> annot then (

src/analyses/extractPthread.ml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -711,16 +711,13 @@ module Codegen = struct
711711
let checkStatus =
712712
"("
713713
^ ( String.concat " op2 "
714-
@@ List.of_enum
715-
@@ (0 --^ thread_count)
716-
/@ fun i -> "status[" ^ string_of_int i ^ "] op1 v" )
714+
(List.init thread_count (fun i -> "status[" ^ string_of_int i ^ "] op1 v")) )
717715
^ ")"
718716
in
719717
let allTasks =
720718
"("
721719
^ ( String.concat " && "
722-
@@ List.of_enum
723-
@@ ((0 --^ thread_count) /@ fun i -> "prop(" ^ string_of_int i ^ ")") )
720+
(List.init thread_count (fun i -> "prop(" ^ string_of_int i ^ ")")) )
724721
^ ")"
725722
in
726723

src/cdomains/apron/linearTwoVarEqualityDomain.apron.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,8 @@ struct
505505
| (None, o1,d1), (None ,o2,d2)-> lhs, (if Z.(zero = ((o1*d2)-(o2*d1))) then Q.one else Q.zero), Q.zero, r1, r2 (* only two equivalence classes: constants with matching values or constants with different values *)
506506
)
507507
in
508-
let table = List.of_enum @@ EConj.IntMap.values @@ EConj.IntMap.merge joinfunction (snd ad) (snd bd) in
508+
let joined = EConj.IntMap.merge joinfunction (snd ad) (snd bd) in
509+
let table = joined |> EConj.IntMap.to_seq |> Seq.map snd |> List.of_seq in
509510
(* compare two variables for grouping depending on affine function parameters a, b and reference variable indices *)
510511
let cmp_z (_, ai, bi, t1i, t2i) (_, aj, bj, t1j, t2j) =
511512
let cmp_ref = Option.compare ~cmp:(fun x y -> Int.compare (snd x) (snd y)) in

0 commit comments

Comments
 (0)