Skip to content

Commit 44d2b76

Browse files
committed
Fix bitfield witness invariants for _Bool and unsigned types
1 parent 9a7c13d commit 44d2b76

File tree

3 files changed

+17
-52
lines changed

3 files changed

+17
-52
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -635,17 +635,27 @@ module BitfieldFunctor (Ints_t : IntOps.IntOps): Bitfield_SOverflow with type in
635635
if def0 =: BArith.zero_mask then
636636
Invariant.none
637637
else (
638-
let def0 = kintegerCilint ik (Ints_t.to_bigint def0) in
639-
Invariant.of_exp (BinOp (Eq, (BinOp (BAnd, e, def0, ik_type)), kintegerCilint ik Z.zero, intType))
638+
let def0 = Ints_t.to_bigint def0 in
639+
if fitsInInt ik def0 then ( (* At least for _Bool and unsigned types, kintegerCilint can give an incorrect mask if doesn't fit. See https://github.com/goblint/analyzer/pull/1897/changes#r2610251390. *)
640+
let def0 = kintegerCilint ik def0 in
641+
Invariant.of_exp (BinOp (Eq, (BinOp (BAnd, e, def0, ik_type)), kintegerCilint ik Z.zero, intType))
642+
)
643+
else
644+
Invariant.none
640645
)
641646
in
642647
let i2 =
643648
let def1 = o &: (!: z) in
644649
if def1 =: BArith.zero_mask then
645650
Invariant.none
646651
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))
652+
let def1 = Ints_t.to_bigint def1 in
653+
if fitsInInt ik def1 then ( (* At least for _Bool and unsigned types, kintegerCilint can give an incorrect mask if doesn't fit. See https://github.com/goblint/analyzer/pull/1897/changes#r2610251390. *)
654+
let def1 = kintegerCilint ik def1 in
655+
Invariant.of_exp (BinOp (Eq, (BinOp (BAnd, e, def1, ik_type)), def1, intType))
656+
)
657+
else
658+
Invariant.none
649659
)
650660
in
651661
Invariant.(i1 && i2)

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: 3
157+
location invariants: 2
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)1) == (_Bool)0
182-
format: c_expression
183174
- invariant:
184175
type: location_invariant
185176
location:

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

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,46 +11,10 @@
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: 4
14+
loop invariants: 0
1515
flow-insensitive invariants: 0
1616
total generation entries: 1
1717

1818
$ yamlWitnessStrip < witness.yml
1919
- entry_type: invariant_set
20-
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
20+
content: []

0 commit comments

Comments
 (0)