Skip to content

Commit e031370

Browse files
committed
Assert valid state in bitfield domain witness invariant
1 parent f5bbd38 commit e031370

File tree

1 file changed

+29
-32
lines changed

1 file changed

+29
-32
lines changed

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

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -625,41 +625,38 @@ module BitfieldFunctor (Ints_t : IntOps.IntOps): Bitfield_SOverflow with type in
625625
(* Invariant *)
626626

627627
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 (
631-
let open GoblintCil.Cil in
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 = 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
628+
assert (not (BArith.is_invalid (z, o)));
629+
let open GoblintCil.Cil in
630+
let ik_type = TInt (ik, []) in
631+
let i1 =
632+
let def0 = z &: (!: o) in
633+
if def0 =: BArith.zero_mask then
634+
Invariant.none
635+
else (
636+
let def0 = Ints_t.to_bigint def0 in
637+
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. *)
638+
let def0 = kintegerCilint ik def0 in
639+
Invariant.of_exp (BinOp (Eq, (BinOp (BAnd, e, def0, ik_type)), kintegerCilint ik Z.zero, intType))
645640
)
646-
in
647-
let i2 =
648-
let def1 = o &: (!: z) in
649-
if def1 =: BArith.zero_mask then
641+
else
650642
Invariant.none
651-
else (
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
643+
)
644+
in
645+
let i2 =
646+
let def1 = o &: (!: z) in
647+
if def1 =: BArith.zero_mask then
648+
Invariant.none
649+
else (
650+
let def1 = Ints_t.to_bigint def1 in
651+
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. *)
652+
let def1 = kintegerCilint ik def1 in
653+
Invariant.of_exp (BinOp (Eq, (BinOp (BAnd, e, def1, ik_type)), def1, intType))
659654
)
660-
in
661-
Invariant.(i1 && i2)
662-
)
655+
else
656+
Invariant.none
657+
)
658+
in
659+
Invariant.(i1 && i2)
663660

664661
let starting ik n =
665662
let (min_ik, max_ik) = Size.range ik in

0 commit comments

Comments
 (0)