Skip to content

Commit 153ce28

Browse files
Merge pull request #1675 from goblint/alternative_1673
Enums: Take care in refinement that no new elements appear
2 parents 2178c51 + 2917c92 commit 153ce28

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

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

+13-3
Original file line numberDiff line numberDiff line change
@@ -349,18 +349,28 @@ module Enums : S with type int_t = Z.t = struct
349349
10, QCheck.map pos (BISet.arbitrary ());
350350
] (* S TODO: decide frequencies *)
351351

352+
353+
(* One needs to be exceedingly careful here to not cause new elements to appear that are not originally tracked by the domain *)
354+
(* to avoid breaking the termination guarantee that only constants from the program can appear in exclusion or inclusion sets here *)
355+
(* What is generally safe is shrinking an inclusion set as no new elements appear here. *)
356+
(* What is not safe is growing an exclusion set or switching from an exclusion set to an inclusion set *)
357+
352358
let refine_with_congruence ik a b =
353359
let contains c m x = if Z.equal m Z.zero then Z.equal c x else Z.equal (Z.rem (Z.sub x c) m) Z.zero in
354360
match a, b with
355361
| Inc e, None -> bot_of ik
356362
| Inc e, Some (c, m) -> Inc (BISet.filter (contains c m) e)
357363
| _ -> a
358364

359-
let refine_with_interval ik a b = a (* TODO: refine inclusion (exclusion?) set *)
365+
let refine_with_interval ik a b =
366+
match a, b with
367+
| Inc _, None -> bot_of ik
368+
| Inc e, Some (l, u) -> Inc (BISet.filter (value_in_range (l,u)) e)
369+
| _ -> a
360370

361371
let refine_with_excl_list ik a b =
362-
match b with
363-
| Some (ls, _) -> meet ik a (of_excl_list ik ls) (* TODO: refine with excl range? *)
372+
match a, b with
373+
| Inc _, Some (ls, _) -> meet ik a (of_excl_list ik ls) (* TODO: refine with excl range? *)
364374
| _ -> a
365375

366376
let refine_with_incl_list ik a b =
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// PARAM: --set ana.int.refinement fixpoint --enable ana.int.def_exc --enable ana.int.enums --enable ana.int.interval --set sem.int.signed_overflow assume_none
2+
// NOTIMEOUT: Used to not reach terminate (https://github.com/goblint/analyzer/issues/1671) and (https://github.com/goblint/analyzer/issues/1673)
3+
int main() {
4+
int count = 0;
5+
while (1) {
6+
count++;
7+
count++;
8+
}
9+
}

0 commit comments

Comments
 (0)