Skip to content

Commit

Permalink
fix(BV): Do not call [X.make] on non-subterm, reloaded (#969)
Browse files Browse the repository at this point in the history
This is a follow-up to #954

Somehow convinced myself that the cases where we perform simplifications
were fine because we would only be simplifying into a subterm, but that
is obviously not the case due to negation. Let's just do the safe thing
and always return the original term with the appropriate equalities.

All of this code should be removed in favor of doing these computations
in the relations instead anyways, which would make sure we always treat
[bv2nat] in the same way for literals and after substitution (see also
#824 )
  • Loading branch information
bclement-ocp authored Nov 24, 2023
1 parent cac3498 commit 7363cd0
Show file tree
Hide file tree
Showing 4 changed files with 276 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/lib/reasoners/bitv.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1324,24 +1324,26 @@ module Shostak(X : ALIEN) = struct
let maybe_negate t =
if negated then E.Ints.(~$$Z.(~$1 lsl sz - ~$1) - t) else t
in
begin match E.term_view t with
| { f = Op Int2BV _; _ } ->
(* bv2nat will simplify: we must call [X.make] again *)
E.BV.bv2nat t |> maybe_negate |> X.make
| { ty = Tbitv n; _ } ->
assert (n = sz);
if negated then
(* if we are negated, we will simplify *)
E.BV.bv2nat t |> maybe_negate |> X.make
else
(* bv2nat will *not* simplify: become uninterpreted with interval
information *)
let t = E.BV.bv2nat t |> maybe_negate in
X.term_embed t,
[ E.Ints.(~$0 <= t) ; E.Ints.(t < ~$$Z.(~$1 lsl n)) ]
| { ty; _ } ->
Util.internal_error "expected bitv, got %a" Ty.print ty
end
let t', ctx =
begin match E.term_view t with
| { f = Op Int2BV _; _ } ->
(* bv2nat will simplify: we must call [X.make] again *)
E.BV.bv2nat t |> maybe_negate, []
| { ty = Tbitv n; _ } ->
assert (n = sz);
if negated then
(* if we are negated, we will simplify *)
E.BV.bv2nat t |> maybe_negate, []
else
(* bv2nat will *not* simplify: become uninterpreted with interval
information *)
let t = E.BV.bv2nat t |> maybe_negate in
t, [ E.Ints.(~$0 <= t) ; E.Ints.(t < ~$$Z.(~$1 lsl n)) ]
| { ty; _ } ->
Util.internal_error "expected bitv, got %a" Ty.print ty
end
in
X.term_embed ot, E.Core.eq ot t' :: ctx
| _ ->
(* Note: we can't just call [X.make] on the result of [abstract_to_nat]
because [X.make] should only be called on subterms. If we do it, it
Expand Down
2 changes: 2 additions & 0 deletions tests/bitv/testfile-bitv025.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

unknown
5 changes: 5 additions & 0 deletions tests/bitv/testfile-bitv025.smt2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(set-logic QF_BV)
(declare-fun s () (_ BitVec 32))
(declare-fun t () (_ BitVec 32))
(assert (= (bvshl s (bvnot (bvmul s t))) (_ bv0 32)))
(check-sat)
249 changes: 249 additions & 0 deletions tests/dune.inc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7363cd0

Please sign in to comment.