Skip to content

Commit 4565359

Browse files
committed
Implement minus overflow to smt terms conversion
1 parent bf20fc9 commit 4565359

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/solvers/smt2_incremental/convert_expr_to_smt.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,29 @@ static smt_termt convert_expr_to_smt(const plus_overflow_exprt &plus_overflow)
878878

879879
static smt_termt convert_expr_to_smt(const minus_overflow_exprt &minus_overflow)
880880
{
881+
const smt_termt left = convert_expr_to_smt(minus_overflow.lhs());
882+
const smt_termt right = convert_expr_to_smt(minus_overflow.rhs());
883+
if(operands_are_of_type<unsignedbv_typet>(minus_overflow))
884+
{
885+
return smt_bit_vector_theoryt::unsigned_less_than(left, right);
886+
}
887+
if(operands_are_of_type<signedbv_typet>(minus_overflow))
888+
{
889+
// Overflow has occurred if the operands have the opposing signs and
890+
// subtracting them gives a result having the same signedness as the
891+
// right-hand operand. For example the following would be overflow for cases
892+
// for 8 bit wide bit vectors -
893+
// -128 - 1 == 127
894+
// 127 - (-1) == -128
895+
const smt_termt msb_left = most_significant_bit_is_set(left);
896+
const smt_termt msb_right = most_significant_bit_is_set(right);
897+
return smt_core_theoryt::make_and(
898+
smt_core_theoryt::distinct(msb_left, msb_right),
899+
smt_core_theoryt::equal(
900+
msb_right,
901+
most_significant_bit_is_set(
902+
smt_bit_vector_theoryt::subtract(left, right))));
903+
}
881904
UNIMPLEMENTED_FEATURE(
882905
"Generation of SMT formula for minus overflow expression: " +
883906
minus_overflow.pretty());

0 commit comments

Comments
 (0)