Skip to content

Commit

Permalink
fix(BV): Allow substituting constants
Browse files Browse the repository at this point in the history
Substituting a constant should be a no-op (just like substituting a
variable that is not in the substitution). Somehow this case was missed
in the new version of `apply_sub`. It is fairly hard to trigger this
case however: it can only happen in `apply_subs`, and requires a
C-substitution to be created, which in turn requires a C-variable to be
split during B-variable slicing, and then the C-substitution must be
applied to an equation rooted in a distinct term that contains a
constant. This patch includes a test case where this happens.
  • Loading branch information
bclement-ocp committed Nov 27, 2023
1 parent 1ae67fa commit eec38ff
Show file tree
Hide file tree
Showing 4 changed files with 263 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lib/reasoners/bitv.ml
Original file line number Diff line number Diff line change
Expand Up @@ -921,11 +921,15 @@ module Shostak(X : ALIEN) = struct

(* [assoc_var v sub] is the same as [assoc_var_id] but takes a variable.
Requires: [v] is an unconstrained root variable.
Requires: [v] is an unconstrainted root variable or a constant.
Raises: [Not_found] if [v] is not in the substitution, or if [v] is a
constant.
Requires: the variables in [sub] are unconstrained root variables. *)
let assoc_var v sub =
match v.bv.defn with
| Droot { id; _ } -> assoc_var_id id sub
| Dcte _ -> raise Not_found
| _ -> (* Can only substitute [Droot] variables *) assert false

(* This is a helper function for [slice_vars].
Expand Down
2 changes: 2 additions & 0 deletions tests/bitv/testfile-bitv027.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

unknown
7 changes: 7 additions & 0 deletions tests/bitv/testfile-bitv027.smt2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(set-logic QF_BV)
(declare-const x (_ BitVec 8))
(declare-const y (_ BitVec 8))
; This used to crash
(assert (= (concat #b00000000 (concat x (concat ((_ extract 6 5) x) ((_ extract 3 1) x)))) (concat y (concat y (concat #b00 ((_ extract 6 4) x)))
)))
(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 eec38ff

Please sign in to comment.