diff --git a/src/solvers/flattening/boolbv.cpp b/src/solvers/flattening/boolbv.cpp index b94cd6db0c3..633c7f0baee 100644 --- a/src/solvers/flattening/boolbv.cpp +++ b/src/solvers/flattening/boolbv.cpp @@ -407,7 +407,7 @@ literalt boolbvt::convert_rest(const exprt &expr) CHECK_RETURN(!bv.empty()); const irep_idt type_id = op.type().id(); if(type_id == ID_signedbv || type_id == ID_fixedbv || type_id == ID_floatbv) - return bv[bv.size()-1]; + return bv_utils.sign_bit(bv); if(type_id == ID_unsignedbv) return const_literal(false); } diff --git a/src/solvers/flattening/bv_utils.cpp b/src/solvers/flattening/bv_utils.cpp index 31dd12fea20..7b7933d21db 100644 --- a/src/solvers/flattening/bv_utils.cpp +++ b/src/solvers/flattening/bv_utils.cpp @@ -432,12 +432,11 @@ literalt bv_utilst::overflow_add( // An overflow occurs if the signs of the two operands are the same // and the sign of the sum is the opposite. - literalt old_sign=op0[op0.size()-1]; - literalt sign_the_same=prop.lequal(op0[op0.size()-1], op1[op1.size()-1]); + literalt old_sign = sign_bit(op0); + literalt sign_the_same = prop.lequal(sign_bit(op0), sign_bit(op1)); bvt result=add(op0, op1); - return - prop.land(sign_the_same, prop.lxor(result[result.size()-1], old_sign)); + return prop.land(sign_the_same, prop.lxor(sign_bit(result), old_sign)); } else if(rep==representationt::UNSIGNED) { @@ -457,7 +456,7 @@ literalt bv_utilst::overflow_sub( // x is negative, always representable, and // thus not an overflow. literalt op1_is_int_min=is_int_min(op1); - literalt op0_is_negative=op0[op0.size()-1]; + literalt op0_is_negative = sign_bit(op0); return prop.lselect(op1_is_int_min, @@ -557,7 +556,7 @@ bvt bv_utilst::shift(const bvt &src, const shiftt s, std::size_t dist) case shiftt::SHIFT_ARIGHT: // src.size()-i won't underflow as i