@@ -85,8 +85,11 @@ bvt boolbvt::conversion_failed(const exprt &expr)
8585 ignoring (expr);
8686
8787 // try to make it free bits
88- std::size_t width=boolbv_width (expr.type ());
89- return prop.new_variables (width);
88+ // TODO we likely end up in this path when an earlier call to boolbv_width
89+ // failed
90+ const auto &width_opt = boolbv_width (expr.type ());
91+ CHECK_RETURN (width_opt.has_value ());
92+ return prop.new_variables (*width_opt);
9093}
9194
9295// / Converts an expression into its gate-level representation and returns a
@@ -234,11 +237,12 @@ bvt boolbvt::convert_bitvector(const exprt &expr)
234237
235238bvt boolbvt::convert_array_comprehension (const array_comprehension_exprt &expr)
236239{
237- std::size_t width=boolbv_width (expr.type ());
238-
239- if (width==0 )
240+ const auto &width_opt = boolbv_width (expr.type ());
241+ if (!width_opt.has_value ())
240242 return conversion_failed (expr);
241243
244+ const std::size_t width = *width_opt;
245+
242246 const exprt &array_size = expr.type ().size ();
243247
244248 const auto size = numeric_cast<mp_integer>(array_size);
@@ -276,7 +280,9 @@ bvt boolbvt::convert_array_comprehension(const array_comprehension_exprt &expr)
276280bvt boolbvt::convert_symbol (const exprt &expr)
277281{
278282 const typet &type=expr.type ();
279- std::size_t width=boolbv_width (type);
283+ const auto &width_opt = boolbv_width (type);
284+ CHECK_RETURN (width_opt.has_value ());
285+ const std::size_t width = *width_opt;
280286
281287 const irep_idt &identifier = expr.get (ID_identifier);
282288 CHECK_RETURN (!identifier.empty ());
@@ -304,7 +310,9 @@ bvt boolbvt::convert_function_application(
304310 functions.record (expr);
305311
306312 // make it free bits
307- return prop.new_variables (boolbv_width (expr.type ()));
313+ const auto &width_opt = boolbv_width (expr.type ());
314+ CHECK_RETURN (width_opt.has_value ());
315+ return prop.new_variables (*width_opt);
308316}
309317
310318
@@ -515,12 +523,12 @@ bool boolbvt::is_unbounded_array(const typet &type) const
515523 if (unbounded_array==unbounded_arrayt::U_ALL)
516524 return true ;
517525
518- const std:: size_t size = boolbv_width (type);
519- if (size == 0 )
526+ const auto &size_opt = boolbv_width (type);
527+ if (!size_opt. has_value () )
520528 return true ;
521529
522530 if (unbounded_array==unbounded_arrayt::U_AUTO)
523- if (size > MAX_FLATTENED_ARRAY_SIZE)
531+ if (*size_opt > MAX_FLATTENED_ARRAY_SIZE)
524532 return true ;
525533
526534 return false ;
@@ -564,7 +572,9 @@ boolbvt::offset_mapt boolbvt::build_offset_map(const struct_typet &src)
564572 for (const auto &comp : components)
565573 {
566574 dest.push_back (offset);
567- offset += boolbv_width (comp.type ());
575+ const auto &comp_width_opt = boolbv_width (comp.type ());
576+ CHECK_RETURN (comp_width_opt.has_value ());
577+ offset += *comp_width_opt;
568578 }
569579 return dest;
570580}
0 commit comments