Skip to content

Commit 1da5e18

Browse files
Replace throws with invariants in boolbv_floatbv_op
Also slightly clean up one existing invariant
1 parent 5b30185 commit 1da5e18

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/solvers/flattening/boolbv_floatbv_op.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,10 @@ bvt boolbvt::convert_floatbv_op(const exprt &expr)
8888
bvt rounding_mode_as_bv = convert_bv(rounding_mode);
8989

9090
const typet &resolved_type = ns.follow(expr.type());
91-
DATA_INVARIANT(
91+
DATA_INVARIANT_WITH_DIAGNOSTICS(
9292
lhs.type() == resolved_type && rhs.type() == resolved_type,
93-
"float op with mixed types:\n" + expr.pretty());
93+
"both operands of a floating point operator must have the same type",
94+
irep_pretty_diagnosticst{expr});
9495

9596
float_utilst float_utils(prop);
9697

@@ -111,7 +112,7 @@ bvt boolbvt::convert_floatbv_op(const exprt &expr)
111112
else if(expr.id()==ID_floatbv_rem)
112113
return float_utils.rem(lhs_as_bv, rhs_as_bv);
113114
else
114-
throw "unexpected operator "+expr.id_string();
115+
UNREACHABLE;
115116
}
116117
else if(resolved_type.id() == ID_vector || resolved_type.id() == ID_complex)
117118
{
@@ -124,8 +125,10 @@ bvt boolbvt::convert_floatbv_op(const exprt &expr)
124125
std::size_t width = boolbv_width(resolved_type);
125126
std::size_t sub_width=boolbv_width(subtype);
126127

127-
if(sub_width==0 || width%sub_width!=0)
128-
throw "convert_floatbv_op: unexpected vector operand width";
128+
DATA_INVARIANT(
129+
sub_width > 0 && width % sub_width == 0,
130+
"width of a vector subtype must be positive and evenly divide the "
131+
"width of the vector");
129132

130133
std::size_t size=width/sub_width;
131134
bvt result_bv;
@@ -151,10 +154,14 @@ bvt boolbvt::convert_floatbv_op(const exprt &expr)
151154
else if(expr.id()==ID_floatbv_div)
152155
sub_result_bv = float_utils.div(lhs_sub_bv, rhs_sub_bv);
153156
else
154-
assert(false);
155-
156-
assert(sub_result_bv.size() == sub_width);
157-
assert(i * sub_width + sub_width - 1 < result_bv.size());
157+
UNREACHABLE;
158+
159+
INVARIANT(
160+
sub_result_bv.size() == sub_width,
161+
"we constructed a new vector of the right size");
162+
INVARIANT(
163+
i * sub_width + sub_width - 1 < result_bv.size(),
164+
"the sub-bitvector fits into the result bitvector");
158165
std::copy(
159166
sub_result_bv.begin(),
160167
sub_result_bv.end(),

0 commit comments

Comments
 (0)