Skip to content

Commit

Permalink
bv-to-int: fix translation of bvneg (cvc5#8437)
Browse files Browse the repository at this point in the history
The translation of bvneg to integers did not match the comment documenting it, causing cvc5#8413 .
This PR fixes the issue and includes the test from cvc5#8413 as well as a simpler test.
Fixes cvc5#8413 .
  • Loading branch information
yoni206 authored Mar 29, 2022
1 parent cb49e01 commit 3d21e43
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/theory/bv/int_blaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ Node IntBlaster::translateWithChildren(
Assert(oldKind != kind::BITVECTOR_SREM);
Assert(oldKind != kind::BITVECTOR_SMOD);
Assert(oldKind != kind::BITVECTOR_XNOR);
Assert(oldKind != kind::BITVECTOR_NOR);
Assert(oldKind != kind::BITVECTOR_NAND);
Assert(oldKind != kind::BITVECTOR_SUB);
Assert(oldKind != kind::BITVECTOR_REPEAT);
Expand Down Expand Up @@ -1080,8 +1081,8 @@ Node IntBlaster::createBVNegNode(Node n, uint64_t bvsize)
{
// Based on Hacker's Delight section 2-2 equation a:
// -x = ~x+1
Node p2 = pow2(bvsize);
return d_nm->mkNode(kind::SUB, p2, n);
Node bvNotNode = createBVNotNode(n, bvsize);
return createBVAddNode(bvNotNode, d_one, bvsize);
}

Node IntBlaster::createBVNotNode(Node n, uint64_t bvsize)
Expand Down
2 changes: 2 additions & 0 deletions test/regress/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ set(regress_0_tests
regress0/bv/bv_to_int_bvuf_to_intuf.smt2
regress0/bv/bv_to_int_bvuf_to_intuf_sorts.smt2
regress0/bv/bv_to_int_elim_err.smt2
regress0/bv/bv_to_int_issue_8413_1.smt2
regress0/bv/bv_to_int_issue_8413_2.smt2
regress0/bv/bv_to_int_int1.smt2
regress0/bv/bv_to_int_zext.smt2
regress0/bv/bvcomp.cvc.smt2
Expand Down
12 changes: 12 additions & 0 deletions test/regress/cli/regress0/bv/bv_to_int_issue_8413_1.smt2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
; COMMAND-LINE: --solve-bv-as-int=sum
; EXPECT: sat

(set-logic QF_BV)

(declare-fun zero () (_ BitVec 16))
(declare-fun x () (_ BitVec 16))

(assert (= zero (_ bv0 16)))
(assert (= zero (bvneg x)))

(check-sat)
7 changes: 7 additions & 0 deletions test/regress/cli/regress0/bv/bv_to_int_issue_8413_2.smt2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
; COMMAND-LINE: --solve-bv-as-int=sum
; EXPECT: sat

(set-logic QF_BV)
(declare-fun a () (_ BitVec 1))
(assert (= (_ bv0 16) (bvsdiv ((_ zero_extend 8) ((_ zero_extend 7) a)) (bvnor (_ bv0 16) (_ bv0 16)))))
(check-sat)

0 comments on commit 3d21e43

Please sign in to comment.