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())
regress0/bv/inequality05.smt2
regress0/bv/int_to_bv_err_on_demand_1.smt2
regress0/bv/int_to_bv_model.smt2
+ regress0/bv/int_to_bv_model2.smt2
regress0/bv/issue-4075.smt2
regress0/bv/issue-4076.smt2
regress0/bv/issue-4130.smt2