Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Do not call [X.make] on non-subterms for bv2nat #954

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/lib/reasoners/bitv.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ module Shostak(X : ALIEN) = struct
we do so, we may end up in a loop where we repeatedly call [X.make] on a
[BV2Nat] term -- so instead if we are a single [Other] term, we become
uninterpreted. *)
let bv2nat bv =
let bv2nat ot bv =
match bv with
| [{ bv = Other { value = r; negated }; sz }] ->
let t = term_extract r in
Expand All @@ -1342,7 +1342,14 @@ module Shostak(X : ALIEN) = struct
| { ty; _ } ->
Util.internal_error "expected bitv, got %a" Ty.print ty
end
| _ -> abstract_to_nat bv |> X.make
| _ ->
(* 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
causes crashes when `IntervalCalculus.add` assumes that the arguments
of division operators have been added to the `Uf` prior to the
division itself. *)
let t' = abstract_to_nat bv in
X.term_embed ot, [ E.Core.eq ot t' ]

let make t =
let { E.f; xs; _ } = E.term_view t in
Expand All @@ -1357,7 +1364,7 @@ module Shostak(X : ALIEN) = struct
[int2bv] terms, we convert the composition [(bv2nat ((_ int2bv n) x))]
into [(mod x (pow 2 n))]. *)
let r, ctx = Canon.make x in
let r, ctx' = bv2nat r in
let r, ctx' = bv2nat t r in
r, List.rev_append ctx' ctx
| _ ->
let r, ctx = Canon.make t in
Expand Down
2 changes: 2 additions & 0 deletions tests/bitv/testfile-bitv024.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

unknown
4 changes: 4 additions & 0 deletions tests/bitv/testfile-bitv024.smt2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(set-logic ALL)
(declare-const x (_ BitVec 4))
(assert (= (bv2nat ((_ extract 3 2) x)) 0))
(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.

Loading