Skip to content

Commit e011a10

Browse files
authored
Merge pull request #1825 from goblint/biset-reduce
Fix enums bitwise operations crashing in `Inc`-`Exc` cases
2 parents ae53fb0 + 1934d01 commit e011a10

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

src/cdomain/value/cdomains/int/defExcDomain.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ module BISet = struct
77
include SetDomain.Make (IntOps.BigIntOps)
88
let is_singleton s = cardinal s = 1
99

10-
let reduce f s =
11-
BatOption.get_exn (fold (fun x acc -> Option.map (f x) acc) s None) (Invalid_argument "BISet.reduce: empty set")
10+
let map_reduce f g s =
11+
s |> to_seq |> Seq.map f |> BatSeq.reduce g
1212
end
1313

1414
(* The module [Exclusion] constains common functionality about handling of exclusion sets between [DefExc] and [Enums] *)

src/cdomain/value/cdomains/int/enumsDomain.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ module Enums : S with type int_t = Z.t = struct
252252
let b = Int.max (Z.numbits i) (Int.max (Int.abs r1) (Int.abs r2)) in
253253
(-b, b)
254254
in
255-
let r' = BISet.reduce (fun i acc -> R.join (f i) acc) x in (* reduce is safe because arguments are not bot here *)
255+
let r' = BISet.map_reduce f R.join x in (* reduce is safe because arguments are not bot here *)
256256
Exc (BISet.empty (), r')
257257
| Exc (_, ((p1, p2) as p)), Exc (_, ((r1, r2) as r)) ->
258258
begin match p1 >= 0, r1 >= 0 with
@@ -278,7 +278,7 @@ module Enums : S with type int_t = Z.t = struct
278278
(-b, b)
279279
)
280280
in
281-
let r' = BISet.reduce (fun i acc -> R.join (f i) acc) x in (* reduce is safe because arguments are not bot here *)
281+
let r' = BISet.map_reduce f R.join x in (* reduce is safe because arguments are not bot here *)
282282
Exc (BISet.empty (), r')
283283
| Exc (_, r1), Exc (_, r2) -> Exc (BISet.empty (), R.join r1 r2)
284284
| _ -> top_of ikind
@@ -297,7 +297,7 @@ module Enums : S with type int_t = Z.t = struct
297297
else
298298
(-b, b)
299299
in
300-
let r' = BISet.reduce (fun i acc -> R.join (f i) acc) x in (* reduce is safe because arguments are not bot here *)
300+
let r' = BISet.map_reduce f R.join x in (* reduce is safe because arguments are not bot here *)
301301
Exc (BISet.empty (), r')
302302
| Exc (_, (p1, p2)), Exc (_, (r1, r2)) ->
303303
if p1 >= 0 && r1 >= 0 then
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// PARAM: --enable ana.int.enums
2+
3+
int main() {
4+
int r; // rand
5+
int x = r & 1; // NOCRASH
6+
return 0;
7+
}

0 commit comments

Comments
 (0)