Skip to content

Commit 61d85ee

Browse files
committed
Fix bitfield domain producing trivial witness invariants
1 parent 65c8505 commit 61d85ee

File tree

5 files changed

+29
-80
lines changed

5 files changed

+29
-80
lines changed

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

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -624,19 +624,32 @@ module BitfieldFunctor (Ints_t : IntOps.IntOps): Bitfield_SOverflow with type in
624624

625625
(* Invariant *)
626626

627-
let invariant_ikind e ik (z,o) =
628-
if z =: BArith.one_mask && o =: BArith.one_mask then
629-
Invariant.top ()
630-
else if BArith.is_invalid (z,o) then
631-
Invariant.none
632-
else
627+
let invariant_ikind e ik (z, o) =
628+
if BArith.is_invalid (z, o) then
629+
Invariant.none (* TODO: should this ever even happen? *)
630+
else (
633631
let open GoblintCil.Cil in
634-
let def0 = z &: (!: o) in
635-
let def1 = o &: (!: z) in
636-
let (def0, def1) = BatTuple.Tuple2.mapn (kintegerCilint ik) (Ints_t.to_bigint def0, Ints_t.to_bigint def1) in
637-
let exp0 = Invariant.of_exp (BinOp (Eq, (BinOp (BAnd, (UnOp (BNot, e, TInt(ik,[]))), def0, TInt(ik,[]))), def0, intType)) in
638-
let exp1 = Invariant.of_exp (BinOp (Eq, (BinOp (BAnd, e, def1, TInt(ik,[]))), def1, intType)) in
639-
Invariant.meet exp0 exp1
632+
let ik_type = TInt (ik, []) in
633+
let i1 =
634+
let def0 = z &: (!: o) in
635+
if def0 =: BArith.zero_mask then
636+
Invariant.none
637+
else (
638+
let def0 = kintegerCilint ik (Ints_t.to_bigint def0) in
639+
Invariant.of_exp (BinOp (Eq, (BinOp (BAnd, UnOp (BNot, e, ik_type), def0, ik_type)), def0, intType))
640+
)
641+
in
642+
let i2 =
643+
let def1 = o &: (!: z) in
644+
if def1 =: BArith.zero_mask then
645+
Invariant.none
646+
else (
647+
let def1 = kintegerCilint ik (Ints_t.to_bigint def1) in
648+
Invariant.of_exp (BinOp (Eq, (BinOp (BAnd, e, def1, ik_type)), def1, intType))
649+
)
650+
in
651+
Invariant.(i1 && i2)
652+
)
640653

641654
let starting ik n =
642655
let (min_ik, max_ik) = Size.range ik in

tests/regression/56-witness/46-top-bool-invariant.t

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ bitfield only:
154154
dead: 0
155155
total lines: 2
156156
[Info][Witness] witness generation summary:
157-
location invariants: 4
157+
location invariants: 3
158158
loop invariants: 0
159159
flow-insensitive invariants: 0
160160
total generation entries: 1
@@ -171,15 +171,6 @@ bitfield only:
171171
function: main
172172
value: (_Bool)0 <= x
173173
format: c_expression
174-
- invariant:
175-
type: location_invariant
176-
location:
177-
file_name: 46-top-bool-invariant.c
178-
line: 5
179-
column: 3
180-
function: main
181-
value: (x & (_Bool)0) == (_Bool)0
182-
format: c_expression
183174
- invariant:
184175
type: location_invariant
185176
location:

tests/regression/83-bitfield/00-simple-demo.t

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
dead: 0
66
total lines: 13
77
[Info][Witness] witness generation summary:
8-
location invariants: 26
8+
location invariants: 24
99
loop invariants: 0
1010
flow-insensitive invariants: 0
1111
total generation entries: 1
@@ -157,15 +157,6 @@
157157
function: main
158158
value: testvar == 235
159159
format: c_expression
160-
- invariant:
161-
type: location_invariant
162-
location:
163-
file_name: 00-simple-demo.c
164-
line: 28
165-
column: 3
166-
function: main
167-
value: (state & 0) == 0
168-
format: c_expression
169160
- invariant:
170161
type: location_invariant
171162
location:
@@ -202,15 +193,6 @@
202193
function: main
203194
value: testvar == 1
204195
format: c_expression
205-
- invariant:
206-
type: location_invariant
207-
location:
208-
file_name: 00-simple-demo.c
209-
line: 29
210-
column: 1
211-
function: main
212-
value: (state & 0) == 0
213-
format: c_expression
214196
- invariant:
215197
type: location_invariant
216198
location:

tests/regression/83-bitfield/15-svcomp-sum03-2.t

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,49 +11,13 @@
1111
[Warning][Deadcode][CWE-571] condition '1' (possibly inserted by CIL) is always true (15-svcomp-sum03-2.c:10:9-10:10)
1212
[Info][Witness] witness generation summary:
1313
location invariants: 0
14-
loop invariants: 8
14+
loop invariants: 4
1515
flow-insensitive invariants: 0
1616
total generation entries: 1
1717

1818
$ yamlWitnessStrip < witness.yml
1919
- entry_type: invariant_set
2020
content:
21-
- invariant:
22-
type: loop_invariant
23-
location:
24-
file_name: 15-svcomp-sum03-2.c
25-
line: 10
26-
column: 3
27-
function: main
28-
value: (loop1 & 0U) == 0U
29-
format: c_expression
30-
- invariant:
31-
type: loop_invariant
32-
location:
33-
file_name: 15-svcomp-sum03-2.c
34-
line: 10
35-
column: 3
36-
function: main
37-
value: (n1 & 0U) == 0U
38-
format: c_expression
39-
- invariant:
40-
type: loop_invariant
41-
location:
42-
file_name: 15-svcomp-sum03-2.c
43-
line: 10
44-
column: 3
45-
function: main
46-
value: (sn & 0U) == 0U
47-
format: c_expression
48-
- invariant:
49-
type: loop_invariant
50-
location:
51-
file_name: 15-svcomp-sum03-2.c
52-
line: 10
53-
column: 3
54-
function: main
55-
value: (x & 0U) == 0U
56-
format: c_expression
5721
- invariant:
5822
type: loop_invariant
5923
location:

tests/regression/witness/int.t/run.t

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131
line: 12
3232
column: 5
3333
function: main
34-
value: (51 <= i && i <= 99) && ((~ i & (-0x7FFFFFFF-1)) == (-0x7FFFFFFF-1) &&
35-
(i & 0) == 0)
34+
value: (51 <= i && i <= 99) && (~ i & (-0x7FFFFFFF-1)) == (-0x7FFFFFFF-1)
3635
format: c_expression
3736
- invariant:
3837
type: location_invariant

0 commit comments

Comments
 (0)