diff options
author | Mathias Preiner <mathias.preiner@gmail.com> | 2021-08-25 17:50:53 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-26 00:50:53 +0000 |
commit | a81064b538382670f25c87f138961f12def7880a (patch) | |
tree | 7a536209012716bbe4c6fb4aa6c651b47494a3d5 /src | |
parent | 71f025753f734ddade5da333dfe2d144fbc13221 (diff) |
int2bv: Fix conversion of signed bit-vector values. (#7061)
This commit fixes the conversion of signed bit-vector values to integers in the int-to-bv preprocessing pass.
Diffstat (limited to 'src')
-rw-r--r-- | src/preprocessing/passes/int_to_bv.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/preprocessing/passes/int_to_bv.cpp b/src/preprocessing/passes/int_to_bv.cpp index 8c18ccf54..41d52d1ae 100644 --- a/src/preprocessing/passes/int_to_bv.cpp +++ b/src/preprocessing/passes/int_to_bv.cpp @@ -217,8 +217,20 @@ Node IntToBV::intToBV(TNode n, NodeMap& cache) result = sm->mkDummySkolem("__intToBV_var", nm->mkBitVectorType(size), "Variable introduced in intToBV pass"); - Node bv2nat = nm->mkNode(kind::BITVECTOR_TO_NAT, result); - d_preprocContext->addSubstitution(current, bv2nat); + /** + * Correctly convert signed/unsigned BV values to Integers as follows + * x < 0 ? -nat(-x) : nat(x) + * where x refers to the bit-vector term `result`. + */ + BitVector bvzero(size, Integer(0)); + Node negResult = nm->mkNode(kind::BITVECTOR_TO_NAT, + nm->mkNode(kind::BITVECTOR_NEG, result)); + Node bv2int = nm->mkNode( + kind::ITE, + nm->mkNode(kind::BITVECTOR_SLT, result, nm->mkConst(bvzero)), + nm->mkNode(kind::UMINUS, negResult), + nm->mkNode(kind::BITVECTOR_TO_NAT, result)); + d_preprocContext->addSubstitution(current, bv2int); } } else if (current.isConst()) |