Skip to content

Commit 5cf4620

Browse files
Merge pull request #26 from ManuelLerchner/precission
added regression test for precission usage
2 parents 2e85cc9 + 65237fd commit 5cf4620

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ module BitfieldFunctor (Ints_t : IntOps.IntOps): SOverflow with type int_t = Int
245245
else
246246
(top_of ik, overflow_info)
247247

248-
let cast_to ?(suppress_ovwarn=false) ?torg ?no_ov t = norm ~suppress_ovwarn t
248+
let cast_to ?(suppress_ovwarn=false) ?torg ?no_ov ik x = norm ~suppress_ovwarn:(suppress_ovwarn || x = top ()) ik x
249249

250250
let join ik b1 b2 = (norm ik @@ (BArith.join b1 b2) ) |> fst
251251

src/cdomain/value/util/precisionUtil.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(** Integer and floating-point option and attribute handling. *)
22

33
(* We define precision by the number of IntDomains activated.
4-
* We currently have 5 types: DefExc, Interval, Enums, Congruence, IntervalSet, Bitfield*)
4+
* We currently have 6 types: DefExc, Interval, Enums, Congruence, IntervalSet, Bitfield*)
55
type int_precision = (bool * bool * bool * bool * bool * bool)
66
(* Same applies for FloatDomain
77
* We currently have only an interval type analysis *)
@@ -57,7 +57,8 @@ let reset_lazy () =
5757
enums := None;
5858
congruence := None;
5959
interval_set := None;
60-
annotation_int_enabled := None
60+
annotation_int_enabled := None;
61+
bitfield := None
6162

6263
(* Thus for maximum precision we activate all Domains *)
6364
let max_int_precision : int_precision = (true, true, true, true, true, true)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// PARAM: --enable ana.int.bitfield --enable annotation.int.enabled
2+
#include <goblint.h>
3+
4+
#define ANY_ERROR 5 // 0b0101
5+
void example1(void) __attribute__((goblint_precision("no-bitfield")));
6+
void example2(void) __attribute__((goblint_precision("bitfield")));
7+
8+
int main() {
9+
example1();
10+
example2();
11+
}
12+
13+
void example1(){
14+
int state;
15+
int r = rand() % 3;
16+
switch (r) {
17+
case 0:
18+
state = 0; /* 0b0000 */
19+
break;
20+
case 1:
21+
state = 8; /* 0b1000 */
22+
break;
23+
default:
24+
state = 10; /* 0b1010 */
25+
break;
26+
}
27+
28+
__goblint_check((state & ANY_ERROR) == 0); //UNKNOWN
29+
}
30+
31+
void example2(){
32+
int state;
33+
int r = rand() % 3;
34+
switch (r) {
35+
case 0:
36+
state = 0; /* 0b0000 */
37+
break;
38+
case 1:
39+
state = 8; /* 0b1000 */
40+
break;
41+
default:
42+
state = 10; /* 0b1010 */
43+
break;
44+
}
45+
46+
__goblint_check((state & ANY_ERROR) == 0); //SUCCESS
47+
}

0 commit comments

Comments
 (0)