57#define UNEXPECTEDCASE(S) PRECONDITION_WITH_DIAGNOSTICS(false, S);
60#define SMT2_TODO(S) PRECONDITION_WITH_DIAGNOSTICS(false, "TODO: " S)
64 const std::string &_benchmark,
65 const std::string &_notes,
66 const std::string &_logic,
163 "variable number shall be within bounds");
169 out <<
"; SMT 2" <<
"\n";
178 out <<
"; Generated for the CPROVER SMT2 solver\n";
break;
186 out <<
"(set-info :source \"" <<
notes <<
"\")" <<
"\n";
188 out <<
"(set-option :produce-models true)" <<
"\n";
194 out <<
"(set-logic " <<
logic <<
")" <<
"\n";
209 out <<
"(check-sat-assuming (";
219 out <<
"; assumptions\n";
230 out <<
"(check-sat)\n";
241 out <<
"(get-value (" <<
id <<
"))"
249 out <<
"; end of SMT2 file"
259 std::size_t number = 0;
260 std::size_t h=pointer_width-1;
261 std::size_t l=pointer_width-
config.bv_encoding.object_bits;
265 const typet &type = o.type();
269 (o.id() != ID_symbol && o.id() != ID_string_constant) ||
270 !size_expr.has_value())
277 out <<
"(assert (=> (= "
278 <<
"((_ extract " << h <<
" " << l <<
") ";
280 out <<
") (_ bv" << number <<
" " <<
config.bv_encoding.object_bits <<
"))"
281 <<
"(= " <<
id <<
" ";
306 if(expr.
id()==ID_symbol)
313 return it->second.value;
316 else if(expr.
id()==ID_nondet_symbol)
323 return it->second.value;
325 else if(expr.
id() == ID_literal)
333 else if(expr.
id() == ID_not)
343 (!expr.
has_operands() && (expr.
id() == ID_struct || expr.
id() == ID_array)))
355 op = std::move(eval_op);
390 if(s.size()>=2 && s[0]==
'#' && s[1]==
'b')
395 else if(s.size()>=2 && s[0]==
'#' && s[1]==
'x')
402 std::size_t
pos = s.find(
".");
403 if(
pos != std::string::npos)
406 if(type.
id() == ID_rational)
414 else if(type.
id() == ID_real)
425 "smt2_convt::parse_literal parsed a number with a decimal point "
434 else if(src.
get_sub().size()==2 &&
439 else if(src.
get_sub().size()==3 &&
442 src.
get_sub()[1].id_string().substr(0, 2)==
"bv")
447 type.
id() == ID_rational && src.
get_sub().size() == 3 &&
458 else if(src.
get_sub().size()==4 &&
461 if(type.
id()==ID_floatbv)
476 s1_int << (floatbv_type.
get_e() + floatbv_type.
get_f()),
482 else if(src.
get_sub().size()==4 &&
491 else if(src.
get_sub().size()==4 &&
500 else if(src.
get_sub().size()==4 &&
510 src.
get_sub()[0].id() ==
"root-obj")
523 src.
get_sub()[1].id().empty() && src.
get_sub()[1].get_sub().size() == 3 &&
524 src.
get_sub()[1].get_sub()[0].id() ==
"+",
525 "unexpected root-obj expression",
532 !
failed,
"failed to parse rational constant coefficient", src.
pretty());
536 sum_lhs.
get_sub()[0].id() ==
"^" && sum_lhs.
get_sub()[1].id() ==
"x",
537 "unexpected first operand to root-obj",
541 degree > 0,
"polynomial degree must be positive", src.
pretty());
542 std::vector<rationalt> coefficients{degree + 1,
rationalt{}};
543 coefficients.front() = constant_coeff;
549 if(type.
id()==ID_signedbv ||
550 type.
id()==ID_unsignedbv ||
551 type.
id()==ID_c_enum ||
552 type.
id()==ID_c_bool)
556 else if(type.
id()==ID_c_enum_tag)
562 result.
type() = type;
565 else if(type.
id()==ID_fixedbv ||
566 type.
id()==ID_floatbv)
572 type.
id() == ID_integer || type.
id() == ID_natural ||
573 type.
id() == ID_rational || type.
id() == ID_real)
577 else if(type.
id() == ID_range)
583 "smt2_convt::parse_literal should not be of unsupported type " +
591 std::unordered_map<int64_t, exprt> operands_map;
595 auto maybe_default_op = operands_map.find(-1);
597 if(maybe_default_op == operands_map.end())
600 default_op = maybe_default_op->second;
603 if(maybe_size.has_value())
605 while(i < maybe_size.value())
607 auto found_op = operands_map.find(i);
608 if(found_op != operands_map.end())
609 operands.emplace_back(found_op->second);
611 operands.emplace_back(default_op);
619 auto found_op = operands_map.find(i);
620 while(found_op != operands_map.end())
622 operands.emplace_back(found_op->second);
624 found_op = operands_map.find(i);
626 operands.emplace_back(default_op);
632 std::unordered_map<int64_t, exprt> *operands_map,
643 if(!index_expr.is_constant())
651 bool failure =
to_integer(index_constant, tempint);
654 long index = tempint.to_long();
656 operands_map->emplace(index, value);
658 else if(src.
get_sub().size()==2 &&
659 src.
get_sub()[0].get_sub().size()==3 &&
660 src.
get_sub()[0].get_sub()[0].id()==
"as" &&
661 src.
get_sub()[0].get_sub()[1].id()==
"const")
665 operands_map->emplace(-1, default_value);
698 if(components.empty())
706 for(std::size_t i=0; i<components.size(); i++)
716 src.
get_sub().size() > j,
"insufficient number of component values");
733 std::size_t offset=0;
735 for(std::size_t i=0; i<components.size(); i++)
740 std::size_t component_width=
boolbv_width(components[i].type());
743 offset + component_width <= total_width,
744 "struct component bits shall be within struct bit vector");
746 std::string component_binary=
748 total_width-offset-component_width, component_width);
753 offset+=component_width;
767 for(
const auto &binding : src.
get_sub()[1].get_sub())
769 const irep_idt &name = binding.get_sub()[0].id();
780 return parse_rec(bindings_it->second, type);
784 type.
id() == ID_signedbv || type.
id() == ID_unsignedbv ||
785 type.
id() == ID_integer || type.
id() == ID_rational ||
786 type.
id() == ID_natural || type.
id() == ID_real || type.
id() == ID_c_enum ||
787 type.
id() == ID_c_enum_tag || type.
id() == ID_fixedbv ||
788 type.
id() == ID_floatbv || type.
id() == ID_c_bool || type.
id() == ID_range)
792 else if(type.
id()==ID_bool)
794 if(src.
id()==ID_1 || src.
id()==ID_true)
796 else if(src.
id()==ID_0 || src.
id()==ID_false)
799 else if(type.
id()==ID_pointer)
815 else if(type.
id()==ID_struct)
819 else if(type.
id() == ID_struct_tag)
824 struct_expr.type() = type;
825 return std::move(struct_expr);
827 else if(type.
id()==ID_union)
831 else if(type.
id() == ID_union_tag)
835 union_expr.type() = type;
838 else if(type.
id()==ID_array)
852 expr.
id() == ID_string_constant || expr.
id() == ID_label)
854 const std::size_t object_bits =
config.bv_encoding.object_bits;
855 const std::size_t max_objects = std::size_t(1) << object_bits;
858 if(object_id >= max_objects)
861 "too many addressed objects: maximum number of objects is set to 2^n=" +
862 std::to_string(max_objects) +
863 " (with n=" + std::to_string(object_bits) +
"); " +
864 "use the `--object-bits n` option to increase the maximum number"};
867 out <<
"(concat (_ bv" << object_id <<
" " << object_bits <<
")"
868 <<
" (_ bv0 " <<
boolbv_width(result_type) - object_bits <<
"))";
870 else if(expr.
id()==ID_index)
879 if(array.
type().
id()==ID_pointer)
881 else if(array.
type().
id()==ID_array)
901 else if(expr.
id()==ID_member)
906 const typet &struct_op_type = struct_op.
type();
909 struct_op_type.
id() == ID_struct || struct_op_type.
id() == ID_struct_tag,
910 "member expression operand shall have struct type");
913 struct_op_type.
id() == ID_struct_tag
930 else if(expr.
id()==ID_if)
945 "operand of address of expression should not be of kind " +
953 if(node.
id() == ID_exists || node.
id() == ID_forall)
967 else if(expr ==
false)
969 else if(expr.
id()==ID_literal)
981 out <<
"; convert\n";
982 out <<
"; Converting var_no " << l.
var_no() <<
" with expr ID of "
992 out <<
"(declare-fun ";
994 out <<
" () Bool)\n";
995 out <<
"(assert (= ";
1007 out <<
"(define-fun " << identifier <<
" () Bool ";
1035 const auto identifier =
1057 for(
auto &assumption : _assumptions)
1068 if(identifier.empty())
1093 std::string result =
"|";
1095 for(
auto ch : identifier)
1103 result+=std::to_string(ch);
1124 const std::string &smt_typename,
1134 const std::string &smt_typename,
1138 "update-" + smt_typename +
"." +
id2string(component_name));
1143 if(type.
id()==ID_floatbv)
1146 return "f"+std::to_string(spec.
width())+
"_"+std::to_string(spec.
f);
1148 else if(type.
id() == ID_bv)
1152 else if(type.
id()==ID_unsignedbv)
1156 else if(type.
id()==ID_c_bool)
1160 else if(type.
id()==ID_signedbv)
1164 else if(type.
id()==ID_bool)
1168 else if(type.
id()==ID_c_enum_tag)
1172 else if(type.
id() == ID_pointer)
1176 else if(type.
id() == ID_struct_tag)
1183 else if(type.
id() == ID_union_tag)
1187 else if(type.
id() == ID_array)
1191 else if(type.
id() == ID_integer)
1195 else if(type.
id() == ID_real)
1199 else if(type.
id() == ID_string)
1203 else if(type.
id() == ID_regex)
1207 else if(type.
id() == ID_mathematical_function)
1209 std::string result =
"MF";
1211 for(
const auto &d : mf.domain())
1213 result +=
"_" +
type2id(mf.codomain());
1233 if(expr.
id()==ID_symbol)
1240 if(expr.
id()==ID_smt2_symbol)
1248 !expr.
operands().empty(),
"non-symbol expressions shall have operands");
1254 for(
const auto &op : expr.
operands())
1282 converter_result->second(expr);
1287 if(expr.
id()==ID_symbol)
1293 else if(expr.
id()==ID_nondet_symbol)
1296 DATA_INVARIANT(!
id.empty(),
"nondet symbol must have identifier");
1299 else if(expr.
id()==ID_smt2_symbol)
1305 else if(expr.
id()==ID_typecast)
1309 else if(expr.
id()==ID_floatbv_typecast)
1313 else if(expr.
id() == ID_floatbv_round_to_integral)
1317 else if(expr.
id()==ID_struct)
1321 else if(expr.
id()==ID_union)
1329 else if(expr.
id() == ID_concatenation)
1333 "concatenation expression should have at least one operand",
1338 for(
const auto &op : expr.
operands())
1341 non_zero_width_ops.push_back(op);
1345 !non_zero_width_ops.empty(),
1346 "concatenation must have at least one non-zero-width operand");
1348 if(non_zero_width_ops.size() == 1)
1357 for(
const auto &op : non_zero_width_ops)
1367 expr.
id() == ID_bitand || expr.
id() == ID_bitor || expr.
id() == ID_bitxor)
1371 "given expression should have at least one operand",
1382 if(expr.
id() == ID_concatenation)
1384 else if(expr.
id() == ID_bitand)
1386 else if(expr.
id() == ID_bitor)
1388 else if(expr.
id() == ID_bitxor)
1391 for(
const auto &op : expr.
operands())
1401 expr.
id() == ID_bitxnor || expr.
id() == ID_bitnand ||
1402 expr.
id() == ID_bitnor)
1411 if(binary_expr.id() == ID_bitxnor)
1413 else if(binary_expr.id() == ID_bitnand)
1415 else if(binary_expr.id() == ID_bitnor)
1423 else if(expr.
operands().size() == 1)
1429 else if(expr.
operands().size() >= 3)
1432 if(expr.
id() == ID_bitxnor)
1434 else if(expr.
id() == ID_bitnand)
1436 else if(expr.
id() == ID_bitnor)
1439 for(
const auto &op : expr.
operands())
1451 expr.
id_string() +
" should have at least one operand");
1454 else if(expr.
id()==ID_bitnot)
1462 else if(expr.
id()==ID_unary_minus)
1465 const auto &type = expr.
type();
1468 type.id() == ID_rational || type.id() == ID_integer ||
1469 type.id() == ID_real)
1475 else if(type.id() == ID_range)
1484 else if(type.id() == ID_floatbv)
1504 else if(expr.
id()==ID_unary_plus)
1509 else if(expr.
id()==ID_sign)
1515 if(op_type.
id()==ID_floatbv)
1519 out <<
"(fp.isNegative ";
1526 else if(op_type.
id()==ID_signedbv)
1532 out <<
" (_ bv0 " << op_width <<
"))";
1537 "sign should not be applied to unsupported type",
1540 else if(expr.
id()==ID_if)
1578 else if(expr.
id()==ID_and ||
1584 "logical and, or, and xor expressions should have Boolean type");
1587 "logical and, or, and xor expressions should have at least two operands");
1589 out <<
"(" << expr.
id();
1590 for(
const auto &op : expr.
operands())
1597 else if(expr.
id() == ID_nand || expr.
id() == ID_nor || expr.
id() == ID_xnor)
1601 "logical nand, nor, xnor expressions should have Boolean type");
1604 "logical nand, nor, xnor expressions should have at least one operand");
1612 if(expr.
id() == ID_nand)
1614 else if(expr.
id() == ID_nor)
1616 else if(expr.
id() == ID_xnor)
1620 for(
const auto &op : expr.
operands())
1629 else if(expr.
id()==ID_implies)
1634 implies_expr.
is_boolean(),
"implies expression should have Boolean type");
1642 else if(expr.
id()==ID_not)
1647 not_expr.
is_boolean(),
"not expression should have Boolean type");
1653 else if(expr.
id() == ID_equal)
1659 "operands of equal expression shall have same type");
1674 else if(expr.
id() == ID_notequal)
1680 "operands of not equal expression shall have same type");
1688 else if(expr.
id()==ID_ieee_float_equal ||
1689 expr.
id()==ID_ieee_float_notequal)
1696 rel_expr.lhs().type() == rel_expr.rhs().type(),
1697 "operands of float equal and not equal expressions shall have same type");
1702 if(rel_expr.id() == ID_ieee_float_notequal)
1711 if(rel_expr.id() == ID_ieee_float_notequal)
1717 else if(expr.
id()==ID_le ||
1724 else if(expr.
id()==ID_plus)
1728 else if(expr.
id()==ID_floatbv_plus)
1732 else if(expr.
id()==ID_minus)
1736 else if(expr.
id()==ID_floatbv_minus)
1740 else if(expr.
id()==ID_div)
1744 else if(expr.
id()==ID_floatbv_div)
1748 else if(expr.
id()==ID_mod)
1752 else if(expr.
id() == ID_euclidean_mod)
1756 else if(expr.
id()==ID_mult)
1760 else if(expr.
id()==ID_floatbv_mult)
1764 else if(expr.
id() == ID_floatbv_rem)
1768 else if(expr.
id() == ID_floatbv_fma)
1772 else if(expr.
id()==ID_address_of)
1778 else if(expr.
id() == ID_array_of)
1783 array_of_expr.type().id() == ID_array,
1784 "array of expression shall have array type");
1788 out <<
"((as const ";
1796 defined_expressionst::const_iterator it =
1802 else if(expr.
id() == ID_array_comprehension)
1807 array_comprehension.type().id() == ID_array,
1808 "array_comprehension expression shall have array type");
1812 out <<
"(lambda ((";
1815 convert_type(array_comprehension.type().size().type());
1827 else if(expr.
id()==ID_index)
1831 else if(expr.
id()==ID_ashr ||
1832 expr.
id()==ID_lshr ||
1838 if(type.
id()==ID_unsignedbv ||
1839 type.
id()==ID_signedbv ||
1842 if(shift_expr.
id() == ID_ashr)
1844 else if(shift_expr.
id() == ID_lshr)
1846 else if(shift_expr.
id() == ID_shl)
1857 const auto &distance_type = shift_expr.
distance().
type();
1858 if(distance_type.id() == ID_integer || distance_type.id() == ID_natural)
1869 distance_type.id() == ID_signedbv ||
1870 distance_type.id() == ID_unsignedbv ||
1871 distance_type.id() == ID_c_enum || distance_type.id() == ID_c_bool)
1876 if(width_op0==width_op1)
1878 else if(width_op0>width_op1)
1880 out <<
"((_ zero_extend " << width_op0-width_op1 <<
") ";
1886 out <<
"((_ extract " << width_op0-1 <<
" 0) ";
1894 "unsupported distance type for " + shift_expr.
id_string() +
": " +
1895 distance_type.id_string());
1902 "unsupported type for " + shift_expr.
id_string() +
": " +
1905 else if(expr.
id() == ID_rol || expr.
id() == ID_ror)
1911 type.
id() == ID_unsignedbv || type.
id() == ID_signedbv ||
1916 if(shift_expr.
id() == ID_rol)
1917 out <<
"((_ rotate_left";
1918 else if(shift_expr.
id() == ID_ror)
1919 out <<
"((_ rotate_right";
1927 if(distance_int_op.has_value())
1929 out << distance_int_op.value();
1933 "distance type for " + shift_expr.
id_string() +
"must be constant");
1942 "unsupported type for " + shift_expr.
id_string() +
": " +
1945 else if(expr.
id() == ID_named_term)
1949 convert(named_term_expr.value());
1953 else if(expr.
id()==ID_with)
1957 else if(expr.
id()==ID_update)
1961 else if(expr.
id() == ID_update_bit)
1965 else if(expr.
id() == ID_update_bits)
1969 else if(expr.
id() == ID_object_address)
1971 out <<
"(object-address ";
1976 else if(expr.
id() == ID_element_address)
1982 auto element_size_expr_opt =
1992 *element_size_expr_opt, element_address_expr.index().type()));
1995 else if(expr.
id() == ID_field_address)
2004 else if(expr.
id()==ID_member)
2008 else if(expr.
id()==ID_pointer_offset)
2013 op.type().id() == ID_pointer,
2014 "operand of pointer offset expression shall be of pointer type");
2016 std::size_t offset_bits =
2021 if(offset_bits>result_width)
2022 offset_bits=result_width;
2025 if(result_width>offset_bits)
2026 out <<
"((_ zero_extend " << result_width-offset_bits <<
") ";
2028 out <<
"((_ extract " << offset_bits-1 <<
" 0) ";
2032 if(result_width>offset_bits)
2035 else if(expr.
id()==ID_pointer_object)
2040 op.type().id() == ID_pointer,
2041 "pointer object expressions should be of pointer type");
2047 out <<
"((_ zero_extend " << ext <<
") ";
2049 out <<
"((_ extract "
2050 << pointer_width-1 <<
" "
2051 << pointer_width-
config.bv_encoding.object_bits <<
") ";
2058 else if(expr.
id() == ID_is_dynamic_object)
2062 else if(expr.
id() == ID_is_invalid_pointer)
2066 out <<
"(= ((_ extract "
2067 << pointer_width-1 <<
" "
2068 << pointer_width-
config.bv_encoding.object_bits <<
") ";
2071 <<
" " <<
config.bv_encoding.object_bits <<
"))";
2073 else if(expr.
id()==ID_string_constant)
2079 else if(expr.
id()==ID_extractbit)
2088 out <<
"(= ((_ extract " << i <<
" " << i <<
") ";
2100 const std::size_t idx_width =
2102 const std::size_t width = std::max(src_width, idx_width);
2104 out <<
"(= ((_ extract 0 0) ";
2106 if(src_width < width)
2107 out <<
"((_ zero_extend " << width - src_width <<
") ";
2109 if(src_width < width)
2112 if(idx_width < width)
2113 out <<
"((_ zero_extend " << width - idx_width <<
") ";
2115 if(idx_width < width)
2120 else if(expr.
id() == ID_onehot)
2124 else if(expr.
id() == ID_onehot0)
2128 else if(expr.
id()==ID_extractbits)
2138 out <<
"((_ extract " << (
bitst{width} + index_i -
bitst{1}) <<
" "
2146 out <<
"(= ((_ extract 0 0) ";
2155 SMT2_TODO(
"smt2: extractbits with non-constant index");
2158 else if(expr.
id()==ID_replication)
2168 out <<
"((_ repeat " << times <<
") ";
2172 else if(expr.
id()==ID_byte_extract_little_endian ||
2173 expr.
id()==ID_byte_extract_big_endian)
2176 false,
"byte_extract ops should be lowered in prepare_for_convert_expr");
2178 else if(expr.
id()==ID_byte_update_little_endian ||
2179 expr.
id()==ID_byte_update_big_endian)
2182 false,
"byte_update ops should be lowered in prepare_for_convert_expr");
2184 else if(expr.
id()==ID_abs)
2190 if(type.
id()==ID_signedbv)
2194 out <<
"(ite (bvslt ";
2196 out <<
" (_ bv0 " << result_width <<
")) ";
2203 else if(type.
id()==ID_fixedbv)
2207 out <<
"(ite (bvslt ";
2209 out <<
" (_ bv0 " << result_width <<
")) ";
2216 else if(type.
id()==ID_floatbv)
2230 else if(expr.
id()==ID_isnan)
2236 if(op_type.
id()==ID_fixedbv)
2238 else if(op_type.
id()==ID_floatbv)
2242 out <<
"(fp.isNaN ";
2252 else if(expr.
id()==ID_isfinite)
2258 if(op_type.
id()==ID_fixedbv)
2260 else if(op_type.
id()==ID_floatbv)
2266 out <<
"(not (fp.isNaN ";
2270 out <<
"(not (fp.isInfinite ";
2282 else if(expr.
id()==ID_isinf)
2288 if(op_type.
id()==ID_fixedbv)
2290 else if(op_type.
id()==ID_floatbv)
2294 out <<
"(fp.isInfinite ";
2304 else if(expr.
id()==ID_isnormal)
2310 if(op_type.
id()==ID_fixedbv)
2312 else if(op_type.
id()==ID_floatbv)
2316 out <<
"(fp.isNormal ";
2329 expr.
id() == ID_overflow_result_plus ||
2330 expr.
id() == ID_overflow_result_minus)
2339 "overflow plus and overflow minus expressions shall be of Boolean type");
2342 expr.
id() == ID_overflow_result_minus;
2343 const typet &op_type = op0.type();
2346 if(op_type.
id()==ID_signedbv)
2349 out <<
"(let ((?sum (";
2350 out << (subtract?
"bvsub":
"bvadd");
2351 out <<
" ((_ sign_extend 1) ";
2354 out <<
" ((_ sign_extend 1) ";
2358 const std::string overflow_condition =
2359 "(not (= ((_ extract " + std::to_string(width) +
" " +
2360 std::to_string(width) +
") ?sum) ((_ extract " +
2361 std::to_string(width - 1) +
" " + std::to_string(width - 1) +
2366 const std::string result =
2367 "((_ extract " + std::to_string(width - 1) +
" 0) ?sum)";
2374 out <<
"(mk-" << smt_typename <<
' ' << result <<
' '
2375 << overflow_condition <<
')';
2383 out <<
"(concat (ite " << overflow_condition <<
" #b1 #b0) " << result
2388 out << overflow_condition;
2392 else if(op_type.
id()==ID_unsignedbv ||
2393 op_type.
id()==ID_pointer)
2396 out <<
"(let ((?sum (" << (subtract ?
"bvsub" :
"bvadd");
2397 out <<
" ((_ zero_extend 1) ";
2400 out <<
" ((_ zero_extend 1) ";
2417 out <<
"(mk-" << smt_typename;
2418 out <<
" ((_ extract " << width - 1 <<
" 0) ?sum) ";
2422 out <<
"((_ extract " << width <<
" " << width <<
") ?sum)";
2433 "overflow check should not be performed on unsupported type",
2438 expr.
id() == ID_overflow_result_mult)
2447 "overflow mult expression shall be of Boolean type");
2452 const typet &op_type = op0.type();
2455 if(op_type.
id()==ID_signedbv)
2457 out <<
"(let ( (prod (bvmul ((_ sign_extend " << width <<
") ";
2459 out <<
") ((_ sign_extend " << width <<
") ";
2464 " " + std::to_string(width * 2) +
")";
2465 const std::string overflow_condition =
2466 "(or (bvsge prod " + bound +
") (bvslt prod (bvneg " + bound +
")))";
2470 const std::string result =
2471 "((_ extract " + std::to_string(width - 1) +
" 0) prod)";
2478 out <<
"(mk-" << smt_typename <<
' ' << result <<
' '
2479 << overflow_condition <<
')';
2487 out <<
"(concat (ite " << overflow_condition <<
" #b1 #b0) " << result
2492 out << overflow_condition;
2496 else if(op_type.
id()==ID_unsignedbv)
2498 out <<
"(let ((prod (bvmul ((_ zero_extend " << width <<
") ";
2500 out <<
") ((_ zero_extend " << width <<
") ";
2504 const std::string overflow_condition =
2506 std::to_string(width * 2) +
"))";
2510 const std::string result =
2511 "((_ extract " + std::to_string(width - 1) +
" 0) prod)";
2518 out <<
"(mk-" << smt_typename <<
' ' << result <<
' '
2519 << overflow_condition <<
')';
2527 out <<
"(concat (ite " << overflow_condition <<
" #b1 #b0) " << result
2532 out << overflow_condition;
2539 "overflow check should not be performed on unsupported type",
2542 else if(expr.
id() == ID_saturating_plus || expr.
id() == ID_saturating_minus)
2544 const bool subtract = expr.
id() == ID_saturating_minus;
2545 const auto &op_type = expr.
type();
2549 if(op_type.id() == ID_signedbv)
2554 out <<
"(let ((?sum (";
2555 out << (subtract ?
"bvsub" :
"bvadd");
2556 out <<
" ((_ sign_extend 1) ";
2559 out <<
" ((_ sign_extend 1) ";
2566 << width <<
" " << width
2569 << (width - 1) <<
" " << (width - 1) <<
") ?sum)";
2573 out <<
"((_ extract " << width - 1 <<
" 0) ?sum) ";
2576 out <<
"(ite (= ((_ extract " << width <<
" " << width <<
") ?sum) #b0) ";
2583 else if(op_type.id() == ID_unsignedbv)
2588 out <<
"(let ((?sum (" << (subtract ?
"bvsub" :
"bvadd");
2589 out <<
" ((_ zero_extend 1) ";
2592 out <<
" ((_ zero_extend 1) ";
2597 out <<
"(ite (= ((_ extract " << width <<
" " << width <<
") ?sum) #b0) ";
2600 out <<
" ((_ extract " << width - 1 <<
" 0) ?sum) ";
2614 "saturating_plus/minus on unsupported type",
2615 op_type.id_string());
2617 else if(expr.
id()==ID_array)
2623 else if(expr.
id()==ID_literal)
2627 else if(expr.
id()==ID_forall ||
2628 expr.
id()==ID_exists)
2634 throw "MathSAT does not support quantifiers";
2636 if(quantifier_expr.
id() == ID_forall)
2638 else if(quantifier_expr.
id() == ID_exists)
2643 for(
const auto &bound : quantifier_expr.
variables())
2666 else if(expr.
id()==ID_let)
2669 const auto &variables = let_expr.
variables();
2670 const auto &values = let_expr.
values();
2675 for(
auto &binding :
make_range(variables).zip(values))
2694 else if(expr.
id()==ID_constraint_select_one)
2697 "smt2_convt::convert_expr: '" + expr.
id_string() +
2698 "' is not yet supported");
2700 else if(expr.
id() == ID_bswap)
2706 "operand of byte swap expression shall have same type as the expression");
2709 out <<
"(let ((bswap_op ";
2714 bswap_expr.
type().
id() == ID_signedbv ||
2715 bswap_expr.
type().
id() == ID_unsignedbv)
2717 const std::size_t width =
2724 width % bits_per_byte == 0,
2725 "bit width indicated by type of bswap expression should be a multiple "
2726 "of the number of bits per byte");
2728 const std::size_t bytes = width / bits_per_byte;
2737 for(std::size_t
byte = 0;
byte < bytes;
byte++)
2741 out <<
"(bswap_byte_" <<
byte <<
' ';
2742 out <<
"((_ extract " << (
byte * bits_per_byte + (bits_per_byte - 1))
2743 <<
" " << (
byte * bits_per_byte) <<
") bswap_op)";
2752 for(std::size_t
byte = 0;
byte < bytes;
byte++)
2753 out <<
" bswap_byte_" <<
byte;
2764 else if(expr.
id() == ID_popcount)
2768 else if(expr.
id() == ID_count_leading_zeros)
2772 else if(expr.
id() == ID_count_trailing_zeros)
2776 else if(expr.
id() == ID_find_first_set)
2780 else if(expr.
id() == ID_bitreverse)
2784 else if(expr.
id() == ID_zero_extend)
2788 else if(expr.
id() == ID_function_application)
2828 if(function_application_expr.function().id() == ID_symbol)
2832 const auto &args = function_application_expr.arguments();
2842 static const std::map<irep_idt, std::string> flat_string_ops = {
2844 {ID_cprover_string_concat_func,
"str.++"},
2845 {ID_cprover_string_length_func,
"str.len"},
2846 {ID_cprover_string_substring_func,
"str.substr"},
2847 {ID_cprover_string_char_at_func,
"str.at"},
2848 {ID_cprover_string_contains_func,
"str.contains"},
2849 {ID_cprover_string_is_prefix_func,
"str.prefixof"},
2850 {ID_cprover_string_is_suffix_func,
"str.suffixof"},
2851 {ID_cprover_string_replace_func,
"str.replace"},
2852 {ID_cprover_string_equal_func,
"="},
2854 {ID_cprover_string_to_regex_func,
"str.to_re"},
2855 {ID_cprover_string_in_regex_func,
"str.in_re"},
2856 {ID_cprover_regex_range_func,
"re.range"},
2857 {ID_cprover_regex_concat_func,
"re.++"},
2858 {ID_cprover_regex_star_func,
"re.*"},
2859 {ID_cprover_regex_plus_func,
"re.+"},
2860 {ID_cprover_regex_opt_func,
"re.opt"},
2861 {ID_cprover_regex_union_func,
"re.union"},
2862 {ID_cprover_regex_inter_func,
"re.inter"},
2863 {ID_cprover_regex_comp_func,
"re.comp"},
2864 {ID_cprover_regex_diff_func,
"re.diff"},
2865 {ID_cprover_regex_all_func,
"re.all"},
2866 {ID_cprover_regex_allchar_func,
"re.allchar"},
2867 {ID_cprover_regex_none_func,
"re.none"}};
2869 std::string smt_name;
2870 if(
auto it = flat_string_ops.find(fn_id); it != flat_string_ops.end())
2871 smt_name = it->second;
2874 const bool is_index_of = fn_id == ID_cprover_string_index_of_func;
2875 const bool is_startswith = fn_id == ID_cprover_string_startswith_func;
2876 const bool is_endswith = fn_id == ID_cprover_string_endswith_func;
2877 const bool is_is_empty = fn_id == ID_cprover_string_is_empty_func;
2878 const bool is_regex_loop = fn_id == ID_cprover_regex_loop_func;
2881 !smt_name.empty() || is_index_of || is_startswith || is_endswith ||
2882 is_is_empty || is_regex_loop)
2890 for(
const auto &arg : args)
2892 if(arg.type().id() == ID_array || arg.type().id() == ID_pointer)
2895 "string/regex built-in '" +
id2string(fn_id) +
2896 "' reached the SMT-LIB string lowering with a refined-string "
2897 "(array/pointer) operand; the refined-string representation "
2898 "requires the SAT string solver (--refine-strings)");
2907 out <<
"(str.indexof ";
2912 if(args.size() == 3)
2918 else if(is_startswith || is_endswith)
2923 out << (is_startswith ?
"(str.prefixof " :
"(str.suffixof ");
2929 else if(is_is_empty)
2937 else if(is_regex_loop)
2945 out <<
"((_ re.loop " << lo <<
' ' << hi <<
") ";
2949 else if(args.empty())
2953 out <<
'(' << smt_name;
2954 for(
const auto &arg : args)
2963 else if(function_application_expr.arguments().empty())
2971 for(
auto &op : function_application_expr.arguments())
2979 else if(expr.
id() == ID_cond)
2984 else if(expr.
id() == ID_reduction_and)
2988 else if(expr.
id() == ID_reduction_nand)
2992 else if(expr.
id() == ID_reduction_or)
2996 else if(expr.
id() == ID_reduction_nor)
3000 else if(expr.
id() == ID_reduction_xor)
3016 out <<
"(let ((?rop ";
3022 for(std::size_t i = 0; i < width; i++)
3023 out <<
" ((_ extract " << i <<
" " << i <<
") ?rop)";
3029 else if(expr.
id() == ID_reduction_xnor)
3038 "smt2_convt::convert_expr should not be applied to unsupported "
3049 if(dest_type == src.
type())
3055 if(dest_type.
id()==ID_c_enum_tag)
3059 if(src_type.
id()==ID_c_enum_tag)
3062 if(dest_type.
id()==ID_bool)
3066 src_type.
id() == ID_signedbv || src_type.
id() == ID_unsignedbv ||
3067 src_type.
id() == ID_c_bool || src_type.
id() == ID_fixedbv ||
3068 src_type.
id() == ID_pointer || src_type.
id() == ID_integer ||
3069 src_type.
id() == ID_natural || src_type.
id() == ID_rational ||
3070 src_type.
id() == ID_real)
3078 else if(src_type.
id()==ID_floatbv)
3082 out <<
"(not (fp.isZero ";
3094 else if(dest_type.
id()==ID_c_bool)
3103 out <<
" (_ bv1 " << to_width <<
")";
3104 out <<
" (_ bv0 " << to_width <<
")";
3107 else if(dest_type.
id()==ID_signedbv ||
3108 dest_type.
id()==ID_unsignedbv ||
3109 dest_type.
id()==ID_c_enum ||
3110 dest_type.
id()==ID_bv)
3114 if(src_type.
id()==ID_signedbv ||
3115 src_type.
id()==ID_unsignedbv ||
3116 src_type.
id()==ID_c_bool ||
3117 src_type.
id()==ID_c_enum ||
3118 src_type.
id()==ID_bv)
3122 if(from_width==to_width)
3124 else if(from_width<to_width)
3127 src_type.
id() == ID_signedbv ||
3128 (src_type.
id() == ID_c_enum &&
3130 out <<
"((_ sign_extend ";
3132 out <<
"((_ zero_extend ";
3134 out << (to_width-from_width)
3141 out <<
"((_ extract " << (to_width-1) <<
" 0) ";
3146 else if(src_type.
id()==ID_fixedbv)
3150 std::size_t from_width=fixedbv_type.
get_width();
3157 out <<
"(let ((?tcop ";
3163 if(to_width>from_integer_bits)
3165 out <<
"((_ sign_extend "
3166 << (to_width-from_integer_bits) <<
") ";
3167 out <<
"((_ extract " << (from_width-1) <<
" "
3168 << from_fraction_bits <<
") ";
3174 out <<
"((_ extract " << (from_fraction_bits+to_width-1)
3175 <<
" " << from_fraction_bits <<
") ";
3180 out <<
" (ite (and ";
3183 if(from_fraction_bits == 0)
3187 out <<
"(not (= ((_ extract " << (from_fraction_bits - 1)
3188 <<
" 0) ?tcop) (_ bv0 " << from_fraction_bits <<
")))";
3192 out <<
" (= ((_ extract " << (from_width-1) <<
" " << (from_width-1)
3197 out <<
" (_ bv1 " << to_width <<
") (_ bv0 " << to_width <<
"))";
3201 else if(src_type.
id()==ID_floatbv)
3203 if(dest_type.
id()==ID_bv)
3209 defined_expressionst::const_iterator it =
3220 else if(dest_type.
id()==ID_signedbv)
3224 "typecast unexpected "+src_type.
id_string()+
" -> "+
3227 else if(dest_type.
id()==ID_unsignedbv)
3231 "typecast unexpected "+src_type.
id_string()+
" -> "+
3235 else if(src_type.
id()==ID_bool)
3240 if(dest_type.
id()==ID_fixedbv)
3243 out <<
" (concat (_ bv1 "
3246 "(_ bv0 " << spec.
width <<
")";
3250 out <<
" (_ bv1 " << to_width <<
")";
3251 out <<
" (_ bv0 " << to_width <<
")";
3256 else if(src_type.
id()==ID_pointer)
3260 if(from_width<to_width)
3262 out <<
"((_ sign_extend ";
3263 out << (to_width-from_width)
3270 out <<
"((_ extract " << (to_width-1) <<
" 0) ";
3275 else if(src_type.
id() == ID_integer || src_type.
id() == ID_natural)
3281 out <<
"(_ bv" << i <<
" " << to_width <<
")";
3284 SMT2_TODO(
"can't convert non-constant integer to bitvector");
3287 src_type.
id() == ID_struct ||
3288 src_type.
id() == ID_struct_tag)
3294 "bit vector with of source and destination type shall be equal");
3301 "bit vector with of source and destination type shall be equal");
3306 src_type.
id() == ID_union ||
3307 src_type.
id() == ID_union_tag)
3311 "bit vector with of source and destination type shall be equal");
3314 else if(src_type.
id()==ID_c_bit_field)
3318 if(from_width==to_width)
3329 std::ostringstream e_str;
3330 e_str << src_type.
id() <<
" -> " << dest_type.
id()
3331 <<
" src == " <<
format(src);
3335 else if(dest_type.
id()==ID_fixedbv)
3342 src_type.
id() == ID_unsignedbv || src_type.
id() == ID_signedbv ||
3343 src_type.
id() == ID_c_enum || src_type.
id() == ID_c_bool)
3350 if(from_width==to_integer_bits)
3352 else if(from_width>to_integer_bits)
3355 out <<
"((_ extract " << (to_integer_bits-1) <<
" 0) ";
3363 from_width < to_integer_bits,
3364 "from_width should be smaller than to_integer_bits as other case "
3365 "have been handled above");
3367 src_type.
id() == ID_unsignedbv || src_type.
id() == ID_c_bool ||
3368 (src_type.
id() == ID_c_enum &&
3369 to_c_enum_type(src_type).underlying_type().
id() == ID_unsignedbv))
3371 out <<
"((_ zero_extend " << (to_integer_bits - from_width) <<
") ";
3377 out <<
"((_ sign_extend "
3378 << (to_integer_bits-from_width) <<
") ";
3384 out <<
"(_ bv0 " << to_fraction_bits <<
")";
3387 else if(src_type.
id()==ID_bool)
3389 out <<
"(concat (concat"
3390 <<
" (_ bv0 " << (to_integer_bits-1) <<
") ";
3396 else if(src_type.
id()==ID_fixedbv)
3401 std::size_t from_width=from_fixedbv_type.
get_width();
3403 out <<
"(let ((?tcop ";
3409 if(to_integer_bits<=from_integer_bits)
3411 out <<
"((_ extract "
3412 << (from_fraction_bits+to_integer_bits-1) <<
" "
3413 << from_fraction_bits
3419 to_integer_bits > from_integer_bits,
3420 "to_integer_bits should be greater than from_integer_bits as the"
3421 "other case has been handled above");
3422 out <<
"((_ sign_extend "
3423 << (to_integer_bits-from_integer_bits)
3425 << (from_width-1) <<
" "
3426 << from_fraction_bits
3432 if(to_fraction_bits<=from_fraction_bits)
3434 out <<
"((_ extract "
3435 << (from_fraction_bits-1) <<
" "
3436 << (from_fraction_bits-to_fraction_bits)
3442 to_fraction_bits > from_fraction_bits,
3443 "to_fraction_bits should be greater than from_fraction_bits as the"
3444 "other case has been handled above");
3445 out <<
"(concat ((_ extract "
3446 << (from_fraction_bits-1) <<
" 0) ";
3449 <<
" (_ bv0 " << to_fraction_bits-from_fraction_bits
3458 else if(dest_type.
id()==ID_pointer)
3462 if(src_type.
id()==ID_pointer)
3468 src_type.
id() == ID_unsignedbv || src_type.
id() == ID_signedbv ||
3469 src_type.
id() == ID_bv)
3475 if(from_width==to_width)
3477 else if(from_width<to_width)
3479 out <<
"((_ sign_extend "
3480 << (to_width-from_width)
3487 out <<
"((_ extract " << to_width - 1 <<
" 0) ";
3495 else if(dest_type.
id()==ID_range)
3498 const auto dest_width =
address_bits(dest_range_type.size());
3499 if(src_type.
id() == ID_range)
3505 const auto src_width =
address_bits(src_range_type.size());
3506 const mp_integer offset = src_range_type.from() - dest_range_type.from();
3509 const bool need_extend = src_width < dest_width;
3510 const bool need_extract = src_width > dest_width;
3511 const bool need_offset = offset != 0;
3518 out <<
"((_ zero_extend " << dest_width - src_width <<
") ";
3522 else if(need_extract)
3524 out <<
"((_ extract " << dest_width - 1 <<
" 0) ";
3539 offset_bits += modulus;
3547 else if(dest_type.
id()==ID_floatbv)
3556 if(src_type.
id()==ID_bool)
3566 else if(src_type.
id()==ID_c_bool)
3572 else if(src_type.
id() == ID_bv)
3581 out <<
"((_ to_fp " << dest_floatbv_type.get_e() <<
" "
3582 << dest_floatbv_type.get_f() + 1 <<
") ";
3592 else if(dest_type.
id() == ID_integer || dest_type.
id() == ID_natural)
3594 if(src_type.
id()==ID_bool)
3603 else if(dest_type.
id()==ID_c_bit_field)
3608 if(from_width==to_width)
3617 else if(dest_type.
id() == ID_rational)
3619 if(src_type.
id() == ID_signedbv)
3628 "Unknown typecast " + src_type.
id_string() +
" -> rational");
3642 if(dest_type.
id()==ID_floatbv)
3644 if(src_type.
id()==ID_floatbv)
3671 out <<
"((_ to_fp " << dst.
get_e() <<
" "
3672 << dst.
get_f() + 1 <<
") ";
3681 else if(src_type.
id()==ID_unsignedbv)
3702 out <<
"((_ to_fp_unsigned " << dst.
get_e() <<
" "
3703 << dst.
get_f() + 1 <<
") ";
3712 else if(src_type.
id()==ID_signedbv)
3720 out <<
"((_ to_fp " << dst.
get_e() <<
" "
3721 << dst.
get_f() + 1 <<
") ";
3730 else if(src_type.
id()==ID_c_enum_tag)
3744 else if(dest_type.
id()==ID_signedbv)
3749 out <<
"((_ fp.to_sbv " << dest_width <<
") ";
3758 else if(dest_type.
id()==ID_unsignedbv)
3763 out <<
"((_ fp.to_ubv " << dest_width <<
") ";
3786 out <<
"(fp.roundToIntegral ";
3799 expr.
type().
id() == ID_struct_tag
3807 components.size() == expr.
operands().size(),
3808 "number of struct components as indicated by the struct type shall be equal"
3809 "to the number of operands of the struct expression");
3811 DATA_INVARIANT(!components.empty(),
"struct shall have struct components");
3815 const std::string &smt_typename =
datatype_map.at(struct_type);
3818 out <<
"(mk-" << smt_typename;
3821 for(struct_typet::componentst::const_iterator
3822 it=components.begin();
3823 it!=components.end();
3836 auto convert_operand = [
this](
const exprt &op) {
3840 else if(op.type().id() == ID_bool)
3847 std::size_t n_concat = 0;
3848 for(std::size_t i = components.size(); i > 1; i--)
3858 convert_operand(expr.
operands()[i - 1]);
3864 convert_operand(expr.
op0());
3866 out << std::string(n_concat,
')');
3874 const auto &size_expr = array_type.
size();
3879 if(!size_expr.is_constant())
3882 "cannot flatten an array of non-constant size to a bit-vector; such an "
3883 "array can only be encoded with the SMT-LIB array theory");
3889 out <<
"(let ((?far ";
3897 out <<
"(select ?far ";
3919 if(total_width==member_width)
3927 total_width > member_width,
3928 "total_width should be greater than member_width as member_width can be"
3929 "at most as large as total_width and the other case has been handled "
3933 << (total_width-member_width) <<
") ";
3943 if(expr_type.
id()==ID_unsignedbv ||
3944 expr_type.
id()==ID_signedbv ||
3945 expr_type.
id()==ID_bv ||
3946 expr_type.
id()==ID_c_enum ||
3947 expr_type.
id()==ID_c_enum_tag ||
3948 expr_type.
id()==ID_c_bool ||
3949 expr_type.
id()==ID_c_bit_field)
3955 out <<
"(_ bv" << value
3956 <<
" " << width <<
")";
3958 else if(expr_type.
id()==ID_fixedbv)
3964 out <<
"(_ bv" << v <<
" " << spec.
width <<
")";
3966 else if(expr_type.
id()==ID_floatbv)
3979 size_t e=floatbv_type.
get_e();
3980 size_t f=floatbv_type.
get_f()+1;
3986 out <<
"((_ to_fp " << e <<
" " << f <<
")"
3992 out <<
"(_ NaN " << e <<
" " << f <<
")";
3997 out <<
"(_ -oo " << e <<
" " << f <<
")";
3999 out <<
"(_ +oo " << e <<
" " << f <<
")";
4009 <<
"#b" << binaryString.substr(0, 1) <<
" "
4010 <<
"#b" << binaryString.substr(1, e) <<
" "
4011 <<
"#b" << binaryString.substr(1+e, f-1) <<
")";
4019 out <<
"(_ bv" << v <<
" " << spec.
width() <<
")";
4022 else if(expr_type.
id()==ID_pointer)
4036 out <<
"(_ bv" << value <<
" " << width <<
")";
4039 else if(expr_type.
id()==ID_bool)
4043 else if(expr ==
false)
4048 else if(expr_type.
id()==ID_array)
4054 else if(expr_type.
id()==ID_rational)
4057 const bool negative =
has_prefix(value,
"-");
4062 value = value.substr(1);
4065 size_t pos=value.find(
"/");
4067 if(
pos==std::string::npos)
4068 out << value <<
".0";
4071 out <<
"(/ " << value.substr(0,
pos) <<
".0 "
4072 << value.substr(
pos+1) <<
".0)";
4078 else if(expr_type.
id() == ID_real)
4082 if(value.find(
'.') == std::string::npos)
4085 else if(expr_type.
id()==ID_integer)
4091 out <<
"(- " << value.substr(1, std::string::npos) <<
')';
4095 else if(expr_type.
id() == ID_natural)
4099 else if(expr_type.
id() == ID_range)
4104 out <<
"(_ bv" << (value_int - range_type.from()) <<
" " << width <<
")";
4106 else if(expr_type.
id() == ID_string)
4113 for(
char ch : value)
4115 const auto c =
static_cast<unsigned char>(ch);
4118 else if(c >= 0x20 && c <= 0x7e)
4121 out <<
"\\u{" << std::hex << static_cast<unsigned>(c) << std::dec
4132 if(expr.
type().
id() == ID_integer)
4142 "unsupported type for euclidean_mod: " + expr.
type().
id_string());
4147 if(expr.
type().
id()==ID_unsignedbv ||
4148 expr.
type().
id()==ID_signedbv)
4150 if(expr.
type().
id()==ID_unsignedbv)
4160 else if(expr.
type().
id() == ID_integer)
4166 out <<
"(let ((?ma ";
4170 out <<
")) (let ((?mr (mod (ite (< ?ma 0) (- ?ma) ?ma)";
4171 out <<
" (ite (< ?mb 0) (- ?mb) ?mb)))) (ite (< ?ma 0) (- ?mr) ?mr)))";
4173 else if(expr.
type().
id() == ID_natural)
4188 std::vector<mp_integer> dynamic_objects;
4191 if(dynamic_objects.empty())
4197 out <<
"(let ((?obj ((_ extract "
4198 << pointer_width-1 <<
" "
4199 << pointer_width-
config.bv_encoding.object_bits <<
") ";
4203 if(dynamic_objects.size()==1)
4205 out <<
"(= (_ bv" << dynamic_objects.front()
4206 <<
" " <<
config.bv_encoding.object_bits <<
") ?obj)";
4212 for(
const auto &
object : dynamic_objects)
4213 out <<
" (= (_ bv" <<
object
4214 <<
" " <<
config.bv_encoding.object_bits <<
") ?obj)";
4228 op_type.
id() == ID_unsignedbv || op_type.
id() == ID_bv ||
4229 op_type.
id() == ID_range)
4233 if(expr.
id()==ID_le)
4235 else if(expr.
id()==ID_lt)
4237 else if(expr.
id()==ID_ge)
4239 else if(expr.
id()==ID_gt)
4248 else if(op_type.
id()==ID_signedbv ||
4249 op_type.
id()==ID_fixedbv)
4252 if(expr.
id()==ID_le)
4254 else if(expr.
id()==ID_lt)
4256 else if(expr.
id()==ID_ge)
4258 else if(expr.
id()==ID_gt)
4267 else if(op_type.
id()==ID_floatbv)
4272 if(expr.
id()==ID_le)
4274 else if(expr.
id()==ID_lt)
4276 else if(expr.
id()==ID_ge)
4278 else if(expr.
id()==ID_gt)
4291 op_type.
id() == ID_rational || op_type.
id() == ID_integer ||
4292 op_type.
id() == ID_natural || op_type.
id() == ID_real)
4303 else if(op_type.
id() == ID_pointer)
4311 if(expr.
id() == ID_le)
4313 else if(expr.
id() == ID_lt)
4315 else if(expr.
id() == ID_ge)
4317 else if(expr.
id() == ID_gt)
4336 expr.
type().
id() == ID_rational || expr.
type().
id() == ID_integer ||
4337 expr.
type().
id() == ID_natural || expr.
type().
id() == ID_real)
4342 for(
const auto &op : expr.
operands())
4351 expr.
type().
id() == ID_unsignedbv || expr.
type().
id() == ID_signedbv ||
4352 expr.
type().
id() == ID_fixedbv)
4369 else if(expr.
type().
id() == ID_range)
4384 out <<
" (_ bv" << range_type.from() <<
' ' << width
4392 else if(expr.
type().
id() == ID_floatbv)
4399 else if(expr.
type().
id() == ID_pointer)
4405 if(p.
type().
id() != ID_pointer)
4409 p.
type().
id() == ID_pointer,
4410 "one of the operands should have pointer type");
4414 base_type.id() != ID_empty,
"no pointer arithmetic over void pointers");
4418 element_size_opt.has_value() && *element_size_opt >=
bytest{0});
4419 bytest element_size = *element_size_opt;
4422 out <<
"(let ((?pointerop ";
4428 const std::size_t offset_bits =
4429 pointer_width -
config.bv_encoding.object_bits;
4432 out <<
"((_ extract " << pointer_width - 1 <<
' ' << offset_bits
4433 <<
") ?pointerop) ";
4434 out <<
"(bvadd ((_ extract " << offset_bits - 1 <<
" 0) ?pointerop) ";
4436 if(element_size >=
bytest{2})
4438 out <<
"(bvmul ((_ extract " << offset_bits - 1 <<
" 0) ";
4440 out <<
") (_ bv" << element_size <<
" " << offset_bits <<
"))";
4444 out <<
"((_ extract " << offset_bits - 1 <<
" 0) ";
4483 out <<
"roundNearestTiesToEven";
4485 out <<
"roundTowardNegative";
4487 out <<
"roundTowardPositive";
4489 out <<
"roundTowardZero";
4491 out <<
"roundNearestTiesToAway";
4495 "Rounding mode should have value 0, 1, 2, 3, or 4",
4503 out <<
"(ite (= (_ bv0 " << width <<
") ";
4505 out <<
") roundNearestTiesToEven ";
4507 out <<
"(ite (= (_ bv1 " << width <<
") ";
4509 out <<
") roundTowardNegative ";
4511 out <<
"(ite (= (_ bv2 " << width <<
") ";
4513 out <<
") roundTowardPositive ";
4515 out <<
"(ite (= (_ bv3 " << width <<
") ";
4517 out <<
") roundTowardZero ";
4520 out <<
"roundNearestTiesToAway";
4531 type.
id() == ID_floatbv ||
4532 (type.
id() == ID_complex &&
4537 if(type.
id()==ID_floatbv)
4547 else if(type.
id()==ID_complex)
4554 "type should not be one of the unsupported types",
4564 expr.
type().
id() == ID_integer || expr.
type().
id() == ID_natural ||
4565 expr.
type().
id() == ID_rational || expr.
type().
id() == ID_real)
4573 else if(expr.
type().
id()==ID_unsignedbv ||
4574 expr.
type().
id()==ID_signedbv ||
4575 expr.
type().
id()==ID_fixedbv)
4577 if(expr.
op0().
type().
id()==ID_pointer &&
4583 base_type.id() != ID_empty,
"no pointer arithmetic over void pointers");
4586 element_size_opt.has_value() && *element_size_opt >=
bytest{1});
4587 bytest element_size = *element_size_opt;
4589 if(element_size >=
bytest{2})
4594 "bitvector width of operand shall be equal to the bitvector width of "
4603 if(element_size >=
bytest{2})
4616 else if(expr.
type().
id()==ID_floatbv)
4623 else if(expr.
type().
id()==ID_pointer)
4627 (expr.
op1().
type().
id() == ID_unsignedbv ||
4639 else if(expr.
type().
id() == ID_range)
4646 out <<
"(bvsub (bvsub ";
4650 out <<
") (_ bv" << range_type.from() <<
' ' << width <<
"))";
4659 expr.
type().
id() == ID_floatbv,
4660 "type of ieee floating point expression shall be floatbv");
4678 if(expr.
type().
id()==ID_unsignedbv ||
4679 expr.
type().
id()==ID_signedbv)
4681 if(expr.
type().
id()==ID_unsignedbv)
4691 else if(expr.
type().
id()==ID_fixedbv)
4696 out <<
"((_ extract " << spec.
width-1 <<
" 0) ";
4701 out <<
" (_ bv0 " << fraction_bits <<
")) ";
4703 out <<
"((_ sign_extend " << fraction_bits <<
") ";
4709 else if(expr.
type().
id()==ID_floatbv)
4717 expr.
type().
id() == ID_rational || expr.
type().
id() == ID_integer ||
4718 expr.
type().
id() == ID_natural || expr.
type().
id() == ID_real)
4720 if(expr.
type().
id() == ID_integer)
4725 out <<
"(let ((?da ";
4729 out <<
")) (let ((?dq (div (ite (< ?da 0) (- ?da) ?da)";
4730 out <<
" (ite (< ?db 0) (- ?db) ?db))))";
4731 out <<
" (ite (= (< ?da 0) (< ?db 0)) ?dq (- ?dq))))";
4737 if(expr.
type().
id() == ID_natural)
4754 expr.
type().
id() == ID_floatbv,
4755 "type of ieee floating point expression shall be floatbv");
4786 "expression should have been converted to a variant with two operands");
4788 if(expr.
type().
id()==ID_unsignedbv ||
4789 expr.
type().
id()==ID_signedbv)
4800 else if(expr.
type().
id()==ID_floatbv)
4807 else if(expr.
type().
id()==ID_fixedbv)
4812 out <<
"((_ extract "
4813 << spec.
width+fraction_bits-1 <<
" "
4814 << fraction_bits <<
") ";
4818 out <<
"((_ sign_extend " << fraction_bits <<
") ";
4822 out <<
"((_ sign_extend " << fraction_bits <<
") ";
4829 expr.
type().
id() == ID_rational || expr.
type().
id() == ID_integer ||
4830 expr.
type().
id() == ID_natural || expr.
type().
id() == ID_real)
4834 for(
const auto &op : expr.
operands())
4849 expr.
type().
id() == ID_floatbv,
4850 "type of ieee floating point expression shall be floatbv");
4869 expr.
type().
id() == ID_floatbv,
4870 "type of ieee floating point expression shall be floatbv");
4884 "smt2_convt::convert_floatbv_rem to be implemented when not using "
4892 expr.
type().
id() == ID_floatbv,
4893 "type of ieee floating point expression shall be floatbv");
4915 "with expression should have exactly three operands");
4919 if(expr_type.
id()==ID_array)
4943 out <<
"(let ((distance? ";
4944 out <<
"(bvmul (_ bv" << sub_width <<
" " << array_width <<
") ";
4948 if(array_width>index_width)
4950 out <<
"((_ zero_extend " << array_width-index_width <<
") ";
4956 out <<
"((_ extract " << array_width-1 <<
" 0) ";
4966 out <<
"(bvshl (_ bv" <<
power(2, sub_width) - 1 <<
" " << array_width
4968 out <<
"distance?)) ";
4972 out <<
"((_ zero_extend " << array_width-sub_width <<
") ";
4974 out <<
") distance?)))";
4977 else if(expr_type.
id() == ID_struct || expr_type.
id() == ID_struct_tag)
4980 expr_type.
id() == ID_struct_tag
4987 const irep_idt &component_name=index.
get(ID_component_name);
4991 "struct should have accessed component");
4995 const std::string &smt_typename =
datatype_map.at(expr_type);
5005 auto convert_operand = [
this](
const exprt &op)
5010 else if(op.type().id() == ID_bool)
5022 if(m.
width==struct_width)
5025 convert_operand(value);
5029 out <<
"(let ((?withop ";
5030 convert_operand(expr.
old());
5037 <<
"((_ extract " << (struct_width - 1) <<
" " << m.
width
5039 convert_operand(value);
5046 convert_operand(value);
5047 out <<
" ((_ extract " << (m.
offset - 1) <<
" 0) ?withop))";
5052 out <<
"(concat (concat "
5053 <<
"((_ extract " << (struct_width - 1) <<
" "
5055 convert_operand(value);
5056 out <<
") ((_ extract " << (m.
offset - 1) <<
" 0) ?withop)";
5064 else if(expr_type.
id() == ID_union || expr_type.
id() == ID_union_tag)
5072 if(total_width==member_width)
5079 total_width > member_width,
5080 "total width should be greater than member_width as member_width is at "
5081 "most as large as total_width and the other case has been handled "
5084 out <<
"((_ extract "
5086 <<
" " << member_width <<
") ";
5093 else if(expr_type.
id()==ID_bv ||
5094 expr_type.
id()==ID_unsignedbv ||
5095 expr_type.
id()==ID_signedbv)
5110 "with expects struct, union, or array type, but got "+
5118 SMT2_TODO(
"smt2_convt::convert_update to be implemented");
5135 if(array_op_type.
id()==ID_array)
5170 out <<
"((_ extract " << sub_width-1 <<
" 0) ";
5174 out <<
"(bvmul (_ bv" << sub_width <<
" " << array_width <<
") ";
5178 if(array_width>index_width)
5180 out <<
"((_ zero_extend " << array_width-index_width <<
") ";
5186 out <<
"((_ extract " << array_width-1 <<
" 0) ";
5198 false,
"index with unsupported array type: " + array_op_type.
id_string());
5205 const typet &struct_op_type = struct_op.
type();
5208 if(struct_op_type.
id() == ID_struct || struct_op_type.
id() == ID_struct_tag)
5211 struct_op_type.
id() == ID_struct_tag
5216 struct_type.
has_component(name),
"struct should have accessed component");
5220 const std::string &smt_typename =
datatype_map.at(struct_type);
5234 if(expr.
type().
id() == ID_bool)
5240 if(expr.
type().
id() == ID_bool)
5245 struct_op_type.
id() == ID_union || struct_op_type.
id() == ID_union_tag)
5249 width != 0,
"failed to get union member width");
5255 out <<
"((_ extract " << (width - 1) <<
" 0) ";
5263 out <<
"((_ extract " << (width - 1) <<
" 0) ";
5270 "convert_member on an unexpected type "+struct_op_type.
id_string());
5277 if(type.
id()==ID_bool)
5283 else if(type.
id()==ID_array)
5294 std::size_t n_concat = 0;
5308 out << std::string(n_concat,
')');
5313 else if(type.
id() == ID_struct || type.
id() == ID_struct_tag)
5326 std::size_t n_concat = 0;
5327 for(std::size_t i=components.size(); i>1; i--)
5347 out << std::string(n_concat,
')');
5352 else if(type.
id()==ID_floatbv)
5367 out <<
"(_ bv" << value <<
" " << spec.
width() <<
")";
5372 "flatten2bv of a non-constant FPA-encoded float is unsupported");
5387 if(type.
id()==ID_bool)
5394 else if(type.
id() == ID_array)
5399 out <<
"(let ((?ufop" << nesting <<
" ";
5410 "cannot unflatten arrays of non-constant size");
5421 out <<
"((as const ";
5429 "unflatten relies on `(lambda ...)` for constant arrays "
5430 "when `(as const ...)` is unavailable");
5436 out <<
"(lambda ((?ufidx" << nesting <<
" ";
5442 out <<
"((_ extract " << subtype_width - 1 <<
" "
5443 <<
"0) ?ufop" << nesting <<
")";
5447 std::size_t offset = subtype_width;
5448 for(
mp_integer i = 1; i < size; ++i, offset += subtype_width)
5453 out <<
"((_ extract " << offset + subtype_width - 1 <<
" " << offset
5454 <<
") ?ufop" << nesting <<
")";
5462 else if(type.
id() == ID_struct || type.
id() == ID_struct_tag)
5468 out <<
"(let ((?ufop" << nesting <<
" ";
5473 const std::string &smt_typename =
datatype_map.at(type);
5475 out <<
"(mk-" << smt_typename;
5484 std::size_t offset=0;
5486 for(struct_typet::componentst::const_iterator it = components.begin();
5487 it != components.end();
5497 out <<
"((_ extract " << offset+member_width-1 <<
" "
5498 << offset <<
") ?ufop" << nesting <<
")";
5500 offset+=member_width;
5521 if(expr.
id()==ID_and && value)
5523 for(
const auto &op : expr.
operands())
5528 if(expr.
id()==ID_or && !value)
5530 for(
const auto &op : expr.
operands())
5535 if(expr.
id()==ID_not)
5545 if(expr.
id() == ID_equal && value)
5554 if(equal_expr.
lhs().
id()==ID_symbol)
5566 equal_expr.
lhs() != equal_expr.
rhs() &&
5579 out <<
"; set_to true (equal)\n";
5587 auto emit_definition_body = [&]()
5590 equal_expr.
lhs().
type().
id() != ID_array ||
5603 if(equal_expr.
lhs().
type().
id() == ID_mathematical_function)
5607 out <<
"(declare-fun " << smt2_identifier;
5609 auto &mathematical_function_type =
5615 for(
auto &t : mathematical_function_type.domain())
5629 out <<
"(assert (= " << smt2_identifier <<
' ';
5631 out <<
')' <<
')' <<
'\n';
5644 out <<
"(declare-fun " << smt2_identifier;
5648 out <<
"(assert (= " << smt2_identifier <<
' ';
5649 emit_definition_body();
5654 out <<
"(define-fun " << smt2_identifier;
5658 emit_definition_body();
5674 out <<
"; set_to " << (value?
"true":
"false") <<
"\n"
5685 out << found_literal->second;
5708 exprt lowered_expr = expr;
5715 it->id() == ID_byte_extract_little_endian ||
5716 it->id() == ID_byte_extract_big_endian)
5721 it->id() == ID_byte_update_little_endian ||
5722 it->id() == ID_byte_update_big_endian)
5728 return lowered_expr;
5745 "lower_byte_operators should remove all byte operators");
5752 auto prophecy_r_or_w_ok =
5756 it.mutate() = lowered;
5757 it.next_sibling_or_parent();
5760 auto prophecy_pointer_in_range =
5764 it.mutate() = lowered;
5765 it.next_sibling_or_parent();
5774 return lowered_expr;
5794 if(expr.
id() == ID_exists || expr.
id() == ID_forall)
5796 std::unordered_map<irep_idt, std::optional<identifiert>> shadowed_syms;
5801 for(
const auto &symbol : q_expr.variables())
5803 const auto identifier = symbol.identifier();
5806 shadowed_syms.insert(
5808 id_entry.second ? std::nullopt
5809 : std::optional{id_entry.first->second}});
5812 for(
const auto &[
id, shadowed_val] : shadowed_syms)
5815 if(!shadowed_val.has_value())
5818 previous_entry->second = std::move(*shadowed_val);
5824 for(
const auto &op : expr.
operands())
5827 if(expr.
id()==ID_symbol ||
5828 expr.
id()==ID_nondet_symbol)
5831 if(expr.
type().
id()==ID_code)
5836 if(expr.
id()==ID_symbol)
5839 identifier=
"nondet_"+
5850 out <<
"; find_symbols\n";
5851 out <<
"(declare-fun " << smt2_identifier;
5853 if(expr.
type().
id() == ID_mathematical_function)
5855 auto &mathematical_function_type =
5860 for(
auto &type : mathematical_function_type.domain())
5884 if(expr.
type().
id() == ID_range)
5889 out <<
"(assert (bvule " << smt2_identifier <<
' ';
5896 else if(expr.
id() == ID_array_of)
5903 const auto &array_type = array_of.type();
5907 out <<
"; the following is a substitute for lambda i. x\n";
5908 out <<
"(declare-fun " <<
id <<
" () ";
5915 out <<
"(assert (forall ((i ";
5917 out <<
")) (= (select " <<
id <<
" i) ";
5935 else if(expr.
id() == ID_array_comprehension)
5942 const auto &array_type = array_comprehension.type();
5943 const auto &array_size = array_type.size();
5947 out <<
"(declare-fun " <<
id <<
" () ";
5951 out <<
"; the following is a substitute for lambda i . x(i)\n";
5952 out <<
"; universally quantified initialization of the array\n";
5953 out <<
"(assert (forall ((";
5957 out <<
")) (=> (and (bvule (_ bv0 " <<
boolbv_width(array_size.type())
5964 out <<
")) (= (select " <<
id <<
" ";
5983 else if(expr.
id()==ID_array)
5990 out <<
"; the following is a substitute for an array constructor" <<
"\n";
5991 out <<
"(declare-fun " <<
id <<
" () ";
5997 for(std::size_t i = 0; i < expr.
operands().size(); i++)
5999 out <<
"(assert (= (select " <<
id <<
" ";
6020 else if(expr.
id()==ID_string_constant)
6030 out <<
"; the following is a substitute for a string" <<
"\n";
6031 out <<
"(declare-fun " <<
id <<
" () ";
6035 for(std::size_t i=0; i<tmp.
operands().size(); i++)
6037 out <<
"(assert (= (select " <<
id <<
' ';
6041 out <<
"))" <<
"\n";
6054 out <<
"(declare-fun " <<
id <<
" () ";
6065 (expr.
id() == ID_floatbv_plus ||
6066 expr.
id() == ID_floatbv_minus ||
6067 expr.
id() == ID_floatbv_mult ||
6068 expr.
id() == ID_floatbv_div ||
6069 expr.
id() == ID_floatbv_fma ||
6070 expr.
id() == ID_floatbv_typecast ||
6071 expr.
id() == ID_ieee_float_equal ||
6072 expr.
id() == ID_ieee_float_notequal ||
6073 ((expr.
id() == ID_lt ||
6074 expr.
id() == ID_gt ||
6075 expr.
id() == ID_le ||
6076 expr.
id() == ID_ge ||
6077 expr.
id() == ID_isnan ||
6078 expr.
id() == ID_isnormal ||
6079 expr.
id() == ID_isfinite ||
6080 expr.
id() == ID_isinf ||
6081 expr.
id() == ID_sign ||
6082 expr.
id() == ID_unary_minus ||
6083 expr.
id() == ID_typecast ||
6084 expr.
id() == ID_abs) &&
6091 if(
bvfp_set.insert(function).second)
6093 out <<
"; this is a model for " << expr.
id() <<
" : "
6096 <<
"(define-fun " << function <<
" (";
6098 for(std::size_t i = 0; i < expr.
operands().size(); i++)
6102 out <<
"(op" << i <<
' ';
6112 for(std::size_t i = 0; i < tmp1.
operands().size(); i++)
6128 expr.
type().
id() == ID_bv)
6138 out <<
"(declare-fun " <<
id <<
" () ";
6144 out <<
"(assert (= ";
6145 out <<
"((_ to_fp " << floatbv_type.get_e() <<
" "
6146 << floatbv_type.get_f() + 1 <<
") " <<
id <<
')';
6154 else if(expr.
id() == ID_initial_state)
6156 irep_idt function =
"initial-state";
6160 out <<
"(declare-fun " << function <<
" (";
6167 else if(expr.
id() == ID_evaluate)
6173 out <<
"(declare-fun " << function <<
" (";
6183 expr.
id() == ID_state_is_cstring ||
6184 expr.
id() == ID_state_is_dynamic_object ||
6185 expr.
id() == ID_state_live_object || expr.
id() == ID_state_writeable_object)
6188 expr.
id() == ID_state_is_cstring ?
"state-is-cstring"
6189 : expr.
id() == ID_state_is_dynamic_object ?
"state-is-dynamic-object"
6190 : expr.
id() == ID_state_live_object ?
"state-live-object"
6191 :
"state-writeable-object";
6195 out <<
"(declare-fun " << function <<
" (";
6205 expr.
id() == ID_state_r_ok || expr.
id() == ID_state_w_ok ||
6206 expr.
id() == ID_state_rw_ok)
6208 irep_idt function = expr.
id() == ID_state_r_ok ?
"state-r-ok"
6209 : expr.
id() == ID_state_w_ok ?
"state-w-ok"
6214 out <<
"(declare-fun " << function <<
" (";
6225 else if(expr.
id() == ID_update_state)
6232 out <<
"(declare-fun " << function <<
" (";
6243 else if(expr.
id() == ID_enter_scope_state)
6250 out <<
"(declare-fun " << function <<
" (";
6261 else if(expr.
id() == ID_exit_scope_state)
6268 out <<
"(declare-fun " << function <<
" (";
6277 else if(expr.
id() == ID_allocate)
6283 out <<
"(declare-fun " << function <<
" (";
6292 else if(expr.
id() == ID_reallocate)
6298 out <<
"(declare-fun " << function <<
" (";
6309 else if(expr.
id() == ID_deallocate_state)
6315 out <<
"(declare-fun " << function <<
" (";
6324 else if(expr.
id() == ID_object_address)
6326 irep_idt function =
"object-address";
6330 out <<
"(declare-fun " << function <<
" (String) ";
6335 else if(expr.
id() == ID_field_address)
6341 out <<
"(declare-fun " << function <<
" (";
6350 else if(expr.
id() == ID_element_address)
6356 out <<
"(declare-fun " << function <<
" (";
6375 if(expr.
id() == ID_with)
6377 else if(expr.
id() == ID_if)
6413 if(type.
id()==ID_array)
6426 out <<
"(_ BitVec 1)";
6432 else if(type.
id()==ID_bool)
6436 else if(type.
id() == ID_struct || type.
id() == ID_struct_tag)
6446 out <<
"(_ BitVec " << width <<
")";
6449 else if(type.
id()==ID_code)
6456 else if(type.
id() == ID_union || type.
id() == ID_union_tag)
6463 union_type.
components().empty() || width != 0,
6464 "failed to get width of union");
6466 out <<
"(_ BitVec " << width <<
")";
6468 else if(type.
id()==ID_pointer)
6473 else if(type.
id()==ID_bv ||
6474 type.
id()==ID_fixedbv ||
6475 type.
id()==ID_unsignedbv ||
6476 type.
id()==ID_signedbv ||
6477 type.
id()==ID_c_bool)
6482 else if(type.
id()==ID_c_enum)
6489 else if(type.
id()==ID_c_enum_tag)
6493 else if(type.
id()==ID_floatbv)
6498 out <<
"(_ FloatingPoint "
6499 << floatbv_type.
get_e() <<
" "
6500 << floatbv_type.
get_f() + 1 <<
")";
6505 else if(type.
id()==ID_rational ||
6508 else if(type.
id()==ID_integer)
6510 else if(type.
id() == ID_natural)
6512 else if(type.
id()==ID_complex)
6522 out <<
"(_ BitVec " << width <<
")";
6525 else if(type.
id()==ID_c_bit_field)
6529 else if(type.
id() == ID_state)
6533 else if(type.
id() == ID_range)
6536 if(range_type.empty())
6540 else if(type.
id() == ID_string)
6542 else if(type.
id() == ID_regex)
6552 std::set<irep_idt> recstack;
6558 std::set<irep_idt> &recstack)
6560 if(type.
id()==ID_array)
6566 else if(type.
id()==ID_complex)
6573 const std::string smt_typename =
6577 out <<
"(declare-datatypes ((" << smt_typename <<
" 0)) "
6578 <<
"(((mk-" << smt_typename;
6580 out <<
" (" << smt_typename <<
".imag ";
6584 out <<
" (" << smt_typename <<
".real ";
6591 else if(type.
id() == ID_struct)
6594 bool need_decl=
false;
6598 const std::string smt_typename =
6613 const std::string &smt_typename =
datatype_map.at(type);
6624 out <<
"(declare-datatypes ((" << smt_typename <<
" 0)) "
6625 <<
"(((mk-" << smt_typename <<
" ";
6638 out <<
"))))" <<
"\n";
6655 for(struct_union_typet::componentst::const_iterator
6656 it=components.begin();
6657 it!=components.end();
6664 out <<
"(define-fun "
6666 <<
"((s " << smt_typename <<
") "
6669 out <<
")) " << smt_typename <<
" "
6670 <<
"(mk-" << smt_typename
6673 for(struct_union_typet::componentst::const_iterator
6674 it2=components.begin();
6675 it2!=components.end();
6687 out <<
"))" <<
"\n";
6693 else if(type.
id() == ID_union)
6701 else if(type.
id()==ID_code)
6705 for(
const auto ¶m : parameters)
6710 else if(type.
id()==ID_pointer)
6714 else if(type.
id() == ID_struct_tag)
6717 const irep_idt &
id = struct_tag.get_identifier();
6719 if(recstack.find(
id) == recstack.end())
6721 const auto &base_struct =
ns.follow_tag(struct_tag);
6722 recstack.insert(
id);
6727 else if(type.
id() == ID_union_tag)
6730 const irep_idt &
id = union_tag.get_identifier();
6732 if(recstack.find(
id) == recstack.end())
6734 recstack.insert(
id);
6738 else if(type.
id() == ID_state)
6743 out <<
"(declare-sort state 0)\n";
6746 else if(type.
id() == ID_mathematical_function)
6748 const auto &mathematical_function_type =
6750 for(
auto &d_type : mathematical_function_type.domain())
API to expression classes for bitvectors.
const onehot0_exprt & to_onehot0_expr(const exprt &expr)
Cast an exprt to a onehot0_exprt.
const replication_exprt & to_replication_expr(const exprt &expr)
Cast an exprt to a replication_exprt.
const reduction_xnor_exprt & to_reduction_xnor_expr(const exprt &expr)
Cast an exprt to a reduction_xnor_exprt.
const reduction_nand_exprt & to_reduction_nand_expr(const exprt &expr)
Cast an exprt to a reduction_nand_exprt.
const shift_exprt & to_shift_expr(const exprt &expr)
Cast an exprt to a shift_exprt.
const reduction_and_exprt & to_reduction_and_expr(const exprt &expr)
Cast an exprt to a reduction_and_exprt.
const reduction_or_exprt & to_reduction_or_expr(const exprt &expr)
Cast an exprt to a reduction_or_exprt.
const popcount_exprt & to_popcount_expr(const exprt &expr)
Cast an exprt to a popcount_exprt.
const update_bits_exprt & to_update_bits_expr(const exprt &expr)
Cast an exprt to an update_bits_exprt.
const extractbits_exprt & to_extractbits_expr(const exprt &expr)
Cast an exprt to an extractbits_exprt.
const onehot_exprt & to_onehot_expr(const exprt &expr)
Cast an exprt to a onehot_exprt.
bool can_cast_expr< minus_overflow_exprt >(const exprt &base)
const find_first_set_exprt & to_find_first_set_expr(const exprt &expr)
Cast an exprt to a find_first_set_exprt.
bool can_cast_expr< overflow_result_exprt >(const exprt &base)
const update_bit_exprt & to_update_bit_expr(const exprt &expr)
Cast an exprt to an update_bit_exprt.
const bitnot_exprt & to_bitnot_expr(const exprt &expr)
Cast an exprt to a bitnot_exprt.
const bswap_exprt & to_bswap_expr(const exprt &expr)
Cast an exprt to a bswap_exprt.
const count_leading_zeros_exprt & to_count_leading_zeros_expr(const exprt &expr)
Cast an exprt to a count_leading_zeros_exprt.
const reduction_xor_exprt & to_reduction_xor_expr(const exprt &expr)
Cast an exprt to a reduction_xor_exprt.
const bitreverse_exprt & to_bitreverse_expr(const exprt &expr)
Cast an exprt to a bitreverse_exprt.
const extractbit_exprt & to_extractbit_expr(const exprt &expr)
Cast an exprt to an extractbit_exprt.
const reduction_nor_exprt & to_reduction_nor_expr(const exprt &expr)
Cast an exprt to a reduction_nor_exprt.
const zero_extend_exprt & to_zero_extend_expr(const exprt &expr)
Cast an exprt to a zero_extend_exprt.
const count_trailing_zeros_exprt & to_count_trailing_zeros_expr(const exprt &expr)
Cast an exprt to a count_trailing_zeros_exprt.
const bv_typet & to_bv_type(const typet &type)
Cast a typet to a bv_typet.
const fixedbv_typet & to_fixedbv_type(const typet &type)
Cast a typet to a fixedbv_typet.
const bitvector_typet & to_bitvector_type(const typet &type)
Cast a typet to a bitvector_typet.
const floatbv_typet & to_floatbv_type(const typet &type)
Cast a typet to a floatbv_typet.
const unsignedbv_typet & to_unsignedbv_type(const typet &type)
Cast a typet to an unsignedbv_typet.
const signedbv_typet & to_signedbv_type(const typet &type)
Cast a typet to a signedbv_typet.
bool has_byte_operator(const exprt &src)
Return true iff src or one of its operands contain a byte extract or byte update expression.
Expression classes for byte-level operators.
const byte_update_exprt & to_byte_update_expr(const exprt &expr)
exprt lower_byte_extract(const byte_extract_exprt &src, const namespacet &ns)
Rewrite a byte extract expression to more fundamental operations.
const byte_extract_exprt & to_byte_extract_expr(const exprt &expr)
exprt lower_byte_update(const byte_update_exprt &src, const namespacet &ns)
Rewrite a byte update expression to more fundamental operations.
typet c_bit_field_replacement_type(const c_bit_field_typet &src, const namespacet &ns)
pointer_typet pointer_type(const typet &subtype)
const c_bit_field_typet & to_c_bit_field_type(const typet &type)
Cast a typet to a c_bit_field_typet.
const c_enum_typet & to_c_enum_type(const typet &type)
Cast a typet to a c_enum_typet.
const c_enum_tag_typet & to_c_enum_tag_type(const typet &type)
Cast a typet to a c_enum_tag_typet.
const union_typet & to_union_type(const typet &type)
Cast a typet to a union_typet.
const c_bool_typet & to_c_bool_type(const typet &type)
Cast a typet to a c_bool_typet.
const union_tag_typet & to_union_tag_type(const typet &type)
Cast a typet to a union_tag_typet.
Operator to return the address of an object.
Represents real numbers as roots (zeros) of a polynomial with rational coefficients.
constant_exprt as_expr() const
Thrown when an unexpected error occurs during the analysis (e.g., when the SAT solver returns an erro...
Pointer-typed bitvector constant annotated with the pointer expression that the bitvector is the nume...
Array constructor from list of elements.
typet index_type() const
The type of the index expressions into any instance of this type.
const exprt & size() const
const typet & element_type() const
The type of the elements of the array.
A base class for binary expressions.
A base class for relations, i.e., binary predicates whose two operands have the same type.
Bit-wise negation of bit-vectors.
std::size_t get_width() const
The byte swap expression.
std::size_t get_bits_per_byte() const
std::vector< parametert > parameterst
const parameterst & parameters() const
A constant literal expression.
const irep_idt & get_value() const
bool is_null_pointer() const
Returns true if expr has a pointer type and a value NULL; it also returns true when expr has value ze...
resultt
Result of running the decision procedure.
Boute's Euclidean definition of Modulo – to match SMT-LIB2.
Base class for all expressions.
std::vector< exprt > operandst
bool has_operands() const
Return true if there is at least one operand.
depth_iteratort depth_end()
bool is_boolean() const
Return whether the expression represents a Boolean.
depth_iteratort depth_begin()
bool is_constant() const
Return whether the expression is a constant.
typet & type()
Return the type of the expression.
void visit_post(std::function< void(exprt &)>)
These are post-order traversal visitors, i.e., the visitor is executed on a node after its children h...
The Boolean constant false.
std::size_t get_fraction_bits() const
Fixed-width bit-vector with signed fixed-point interpretation.
std::size_t get_fraction_bits() const
std::size_t get_integer_bits() const
Fused multiply-add expression: round(op0 * op1 + op2) with a single rounding.
exprt & op_multiply_lhs()
exprt & op_multiply_rhs()
Round a floating-point number to an integral value considering the given rounding mode.
Semantic type conversion from/to floating-point formats.
Fixed-width bit-vector with IEEE floating-point interpretation.
std::size_t get_f() const
std::size_t get_e() const
IEEE floating-point operations These have two data operands (op0 and op1) and one rounding mode (op2)...
std::size_t width() const
An IEEE 754 floating-point value, including specificiation.
static ieee_float_valuet minus_infinity(const ieee_float_spect &_spec)
static ieee_float_valuet one(const floatbv_typet &)
constant_exprt to_expr() const
static ieee_float_valuet zero(const floatbv_typet &type)
static ieee_float_valuet NaN(const ieee_float_spect &_spec)
static ieee_float_valuet plus_infinity(const ieee_float_spect &_spec)
The trinary if-then-else operator.
There are a large number of kinds of tree structured or tree-like data in CPROVER.
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
const irep_idt & get(const irep_idt &name) const
const std::string & id_string() const
const irep_idt & id() const
Evaluates to true if the operand is finite.
Evaluates to true if the operand is infinite.
Evaluates to true if the operand is NaN.
Evaluates to true if the operand is a normal number.
binding_exprt::variablest & variables()
convenience accessor for binding().variables()
exprt & where()
convenience accessor for binding().where()
literalt get_literal() const
Extract member of struct or union.
const exprt & struct_op() const
irep_idt get_component_name() const
Modulo defined as lhs-(rhs * truncate(lhs/rhs)).
Binary multiplication Associativity is not specified.
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
const irep_idt & get_identifier() const
Expression for finding the size (in bytes) of the object a pointer points to.
The plus expression Associativity is not specified.
The pointer type These are both 'bitvector_typet' (they have a width) and 'type_with_subtypet' (they ...
const typet & base_type() const
The type of the data what we point to.
A base class for quantifier expressions.
Unbounded, signed rational numbers.
Boolean reduction: XOR (parity) of all bits in the operand.
A base class for shift and rotate operators.
Sign of an expression Predicate is true if _op is negative, false otherwise.
const irep_idt & get_identifier() const
void convert_relation(const binary_relation_exprt &)
bool use_lambda_for_array
void convert_type(const typet &)
void unflatten(wheret, const typet &, unsigned nesting=0)
bool use_array_theory(const exprt &)
void find_symbols(const exprt &expr)
Find and declare symbols used in an expression This function traverses the expression tree and create...
std::size_t number_of_solver_calls
void convert_typecast(const typecast_exprt &expr)
void write_footer()
Writes the end of the SMT file to the smt_convt::out stream.
tvt l_get(literalt l) const
void convert_floatbv_rem(const binary_exprt &expr)
std::unordered_map< irep_idt, irept > current_bindings
resultt dec_solve(const exprt &) override
Implementation of the decision procedure.
std::set< irep_idt > bvfp_set
void convert_address_of_rec(const exprt &expr, const pointer_typet &result_type)
void push() override
Unimplemented.
void convert_is_dynamic_object(const unary_exprt &)
void convert_literal(const literalt)
void convert_floatbv_div(const ieee_float_op_exprt &expr)
void convert_string_literal(const std::string &)
std::size_t get_number_of_solver_calls() const override
Return the number of incremental solver calls.
void convert_floatbv_mult(const ieee_float_op_exprt &expr)
boolbv_widtht boolbv_width
void convert_constant(const constant_exprt &expr)
std::string floatbv_suffix(const exprt &) const
void flatten2bv(const exprt &)
void convert_floatbv_fma(const floatbv_fma_exprt &expr)
void convert_div(const div_exprt &expr)
exprt lower_byte_operators(const exprt &expr)
Lower byte_update and byte_extract operations within expr.
std::string type2id(const typet &) const
void convert_rounding_mode_FPA(const exprt &expr)
Converting a constant or symbolic rounding mode to SMT-LIB.
void convert_floatbv_typecast(const floatbv_typecast_exprt &expr)
struct_exprt parse_struct(const irept &s, const struct_typet &type)
void convert_mult(const mult_exprt &expr)
void convert_update_bit(const update_bit_exprt &)
exprt prepare_for_convert_expr(const exprt &expr)
Perform steps necessary before an expression is passed to convert_expr.
exprt get(const exprt &expr) const override
Return expr with variables replaced by values from satisfying assignment if available.
std::string decision_procedure_text() const override
Return a textual description of the decision procedure.
void convert_floatbv_minus(const ieee_float_op_exprt &expr)
bool use_check_sat_assuming
std::map< object_size_exprt, irep_idt > object_sizes
void define_object_size(const irep_idt &id, const object_size_exprt &expr)
datatype_mapt datatype_map
void convert_mod(const mod_exprt &expr)
static std::string convert_identifier(const irep_idt &identifier)
void convert_floatbv_plus(const ieee_float_op_exprt &expr)
void convert_struct(const struct_exprt &expr)
std::unordered_map< irep_idt, bool > set_values
The values which boolean identifiers have been smt2_convt::set_to or in other words those which are a...
smt2_convt(const namespacet &_ns, const std::string &_benchmark, const std::string &_notes, const std::string &_logic, solvert _solver, std::ostream &_out)
void convert_member(const member_exprt &expr)
void convert_euclidean_mod(const euclidean_mod_exprt &expr)
void convert_index(const index_exprt &expr)
pointer_logict pointer_logic
exprt handle(const exprt &expr) override
Generate a handle, which is an expression that has the same value as the argument in any model that i...
void print_assignment(std::ostream &out) const override
Print satisfying assignment to out.
void walk_array_tree(std::unordered_map< int64_t, exprt > *operands_map, const irept &src, const array_typet &type)
This function walks the SMT output and populates a map with index/value pairs for the array.
void convert_floatbv_round_to_integral(const floatbv_round_to_integral_exprt &)
void set_to(const exprt &expr, bool value) override
For a Boolean expression expr, add the constraint 'expr' if value is true, otherwise add 'not expr'.
static std::string datatype_update_name(const std::string &smt_typename, const irep_idt &component_name)
Build the name of the function that updates component component_name of a value of the datatype named...
exprt parse_rec(const irept &s, const typet &type)
void convert_union(const union_exprt &expr)
exprt parse_union(const irept &s, const union_typet &type)
exprt parse_array(const irept &s, const array_typet &type)
This function is for parsing array output from SMT solvers when "(get-value |???|)" returns an array ...
std::vector< bool > boolean_assignment
void flatten_array(const exprt &)
produce a flat bit-vector for a given array of fixed size
void convert_with(const with_exprt &expr)
std::vector< literalt > assumptions
static std::string datatype_selector_name(const std::string &smt_typename, const irep_idt &component_name)
Build the name of the field selector for component component_name of the datatype named smt_typename.
void convert_plus(const plus_exprt &expr)
defined_expressionst defined_expressions
void pop() override
Currently, only implements a single stack element (no nested contexts).
void convert_update_bits(const update_bits_exprt &)
void find_symbols_rec(const typet &type, std::set< irep_idt > &recstack)
void convert_update(const update_exprt &)
std::set< irep_idt > state_fkt_declared
identifier_mapt identifier_map
void convert_minus(const minus_exprt &expr)
void convert_expr(const exprt &)
constant_exprt parse_literal(const irept &, const typet &type)
const smt2_symbolt & to_smt2_symbol(const exprt &expr)
std::size_t no_boolean_variables
smt2_identifierst smt2_identifiers
void convert_floatbv(const exprt &expr)
literalt convert(const exprt &expr)
array_exprt to_array_expr() const
convert string into array constant
Struct constructor from list of elements.
Structure type, corresponds to C style structs.
const irep_idt & get_name() const
const componentst & components() const
const componentt & get_component(const irep_idt &component_name) const
Get the reference to a component with given name.
bool has_component(const irep_idt &component_name) const
std::vector< componentt > componentst
const irep_idt & get_identifier() const
void identifier(const irep_idt &identifier)
The Boolean constant true.
Semantic type conversion.
static exprt conditional_cast(const exprt &expr, const typet &type)
The type of an expression, extends irept.
Generic base class for unary expressions.
The unary minus expression.
Union constructor from single element.
Fixed-width bit-vector with unsigned binary interpretation.
Thrown when we encounter an instruction, parameters to an instruction etc.
Replaces a sub-range of a bit-vector operand.
exprt lower() const
A lowering to masking, shifting, or.
Replaces a sub-range of a bit-vector operand.
exprt lower() const
A lowering to masking, shifting, or.
Operator to update elements in structs and arrays.
Operator to update elements in structs and arrays.
bool has_prefix(const std::string &s, const std::string &prefix)
bool can_cast_expr(const exprt &base)
Check whether a reference to a generic exprt is of a specific derived class.
auto expr_try_dynamic_cast(TExpr &base) -> typename detail::expr_try_dynamic_cast_return_typet< T, TExpr >::type
Try to cast a reference to a generic exprt to a specific derived class.
Forward depth-first search iterators These iterators' copy operations are expensive,...
exprt make_binary(const exprt &expr)
splits an expression with >=3 operands into nested binary expressions
Deprecated expression utility functions.
bool has_symbol_expr(const exprt &src, const irep_idt &identifier, bool include_bound_symbols)
Returns true if one of the symbol expressions in src has identifier identifier; if include_bound_symb...
exprt float_bv(const exprt &src)
API to expression classes for floating-point arithmetic.
const ieee_float_op_exprt & to_ieee_float_op_expr(const exprt &expr)
Cast an exprt to an ieee_float_op_exprt.
const floatbv_fma_exprt & to_floatbv_fma_expr(const exprt &expr)
const floatbv_round_to_integral_exprt & to_floatbv_round_to_integral_expr(const exprt &expr)
Cast an exprt to a floatbv_round_to_integral_exprt.
const isnormal_exprt & to_isnormal_expr(const exprt &expr)
Cast an exprt to a isnormal_exprt.
const isinf_exprt & to_isinf_expr(const exprt &expr)
Cast an exprt to a isinf_exprt.
const isfinite_exprt & to_isfinite_expr(const exprt &expr)
Cast an exprt to a isfinite_exprt.
const isnan_exprt & to_isnan_expr(const exprt &expr)
Cast an exprt to a isnan_exprt.
const floatbv_typecast_exprt & to_floatbv_typecast_expr(const exprt &expr)
Cast an exprt to a floatbv_typecast_exprt.
const std::string & id2string(const irep_idt &d)
static std::string binary(const constant_exprt &src)
exprt to_expr(const namespacet &ns, const irep_idt &identifier, const std::string &src)
bool is_true(const literalt &l)
literalt const_literal(bool value)
const literal_exprt & to_literal_expr(const exprt &expr)
Cast a generic exprt to a literal_exprt.
double pow(double x, double y)
API to expression classes for 'mathematical' expressions.
const quantifier_exprt & to_quantifier_expr(const exprt &expr)
Cast an exprt to a quantifier_exprt.
const function_application_exprt & to_function_application_expr(const exprt &expr)
Cast an exprt to a function_application_exprt.
const integer_range_typet & to_integer_range_type(const typet &type)
Cast a typet to a integer_range_typet.
const mathematical_function_typet & to_mathematical_function_type(const typet &type)
Cast a typet to a mathematical_function_typet.
const mp_integer string2integer(const std::string &n, unsigned base)
const std::string integer2string(const mp_integer &n, unsigned base)
mp_integer bitwise_or(const mp_integer &a, const mp_integer &b)
bitwise 'or' of two nonnegative integers
const std::string integer2binary(const mp_integer &n, std::size_t width)
named_mp_integert< bits_tagt > bitst
named_mp_integert< bytes_tagt > bytest
const element_address_exprt & to_element_address_expr(const exprt &expr)
Cast an exprt to an element_address_exprt.
const object_address_exprt & to_object_address_expr(const exprt &expr)
Cast an exprt to an object_address_exprt.
const address_of_exprt & to_address_of_expr(const exprt &expr)
Cast an exprt to an address_of_exprt.
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
const pointer_offset_exprt & to_pointer_offset_expr(const exprt &expr)
Cast an exprt to a pointer_offset_exprt.
const pointer_object_exprt & to_pointer_object_expr(const exprt &expr)
Cast an exprt to a pointer_object_exprt.
const field_address_exprt & to_field_address_expr(const exprt &expr)
Cast an exprt to an field_address_exprt.
bool is_zero_width(const typet &type, const namespacet &ns)
Returns true iff type has effective width of zero bits.
std::optional< exprt > size_of_expr(const typet &type, const namespacet &ns)
std::optional< bytest > member_offset(const struct_typet &type, const irep_idt &member, const namespacet &ns)
std::optional< bytest > pointer_offset_size(const typet &type, const namespacet &ns)
Compute the size of a type in bytes, rounding up to full bytes.
exprt pointer_offset(const exprt &pointer)
exprt object_size(const exprt &pointer)
exprt same_object(const exprt &p1, const exprt &p2)
Various predicates over pointers in programs.
Ranges: pair of begin and end iterators, which can be initialized from containers,...
ranget< iteratort > make_range(iteratort begin, iteratort end)
exprt simplify_expr(exprt src, const namespacet &ns)
static bool has_quantifier(const exprt &expr)
static bool is_smt2_simple_identifier(const std::string &identifier)
#define UNEXPECTEDCASE(S)
bool is_smt2_simple_symbol_character(char ch)
Tokenizer for the SMT-LIB v2.6 syntax.
#define CHECK_RETURN(CONDITION)
#define UNREACHABLE
This should be used to mark dead code.
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
#define PRECONDITION(CONDITION)
#define INVARIANT_WITH_DIAGNOSTICS(CONDITION, REASON,...)
Same as invariant, with one or more diagnostics attached Diagnostics can be of any type that has a sp...
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
#define CHECK_RETURN_WITH_DIAGNOSTICS(CONDITION,...)
#define DATA_INVARIANT_WITH_DIAGNOSTICS(CONDITION, REASON,...)
#define UNREACHABLE_BECAUSE(REASON)
auto component(T &struct_expr, const irep_idt &name, const namespacet &ns) -> decltype(struct_expr.op0())
API to expression classes.
const struct_exprt & to_struct_expr(const exprt &expr)
Cast an exprt to a struct_exprt.
const array_of_exprt & to_array_of_expr(const exprt &expr)
Cast an exprt to an array_of_exprt.
const binary_relation_exprt & to_binary_relation_expr(const exprt &expr)
Cast an exprt to a binary_relation_exprt.
const unary_plus_exprt & to_unary_plus_expr(const exprt &expr)
Cast an exprt to a unary_plus_exprt.
const index_exprt & to_index_expr(const exprt &expr)
Cast an exprt to an index_exprt.
const mod_exprt & to_mod_expr(const exprt &expr)
Cast an exprt to a mod_exprt.
const mult_exprt & to_mult_expr(const exprt &expr)
Cast an exprt to a mult_exprt.
const array_comprehension_exprt & to_array_comprehension_expr(const exprt &expr)
Cast an exprt to a array_comprehension_exprt.
const ternary_exprt & to_ternary_expr(const exprt &expr)
Cast an exprt to a ternary_exprt.
const named_term_exprt & to_named_term_expr(const exprt &expr)
Cast an exprt to a named_term_exprt.
const cond_exprt & to_cond_expr(const exprt &expr)
Cast an exprt to a cond_exprt.
const typecast_exprt & to_typecast_expr(const exprt &expr)
Cast an exprt to a typecast_exprt.
const div_exprt & to_div_expr(const exprt &expr)
Cast an exprt to a div_exprt.
const binary_exprt & to_binary_expr(const exprt &expr)
Cast an exprt to a binary_exprt.
const plus_exprt & to_plus_expr(const exprt &expr)
Cast an exprt to a plus_exprt.
const notequal_exprt & to_notequal_expr(const exprt &expr)
Cast an exprt to an notequal_exprt.
const unary_exprt & to_unary_expr(const exprt &expr)
Cast an exprt to a unary_exprt.
const multi_ary_exprt & to_multi_ary_expr(const exprt &expr)
Cast an exprt to a multi_ary_exprt.
const let_exprt & to_let_expr(const exprt &expr)
Cast an exprt to a let_exprt.
const abs_exprt & to_abs_expr(const exprt &expr)
Cast an exprt to a abs_exprt.
const if_exprt & to_if_expr(const exprt &expr)
Cast an exprt to an if_exprt.
const member_exprt & to_member_expr(const exprt &expr)
Cast an exprt to a member_exprt.
const minus_exprt & to_minus_expr(const exprt &expr)
Cast an exprt to a minus_exprt.
const union_exprt & to_union_expr(const exprt &expr)
Cast an exprt to a union_exprt.
const constant_exprt & to_constant_expr(const exprt &expr)
Cast an exprt to a constant_exprt.
const not_exprt & to_not_expr(const exprt &expr)
Cast an exprt to an not_exprt.
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
const with_exprt & to_with_expr(const exprt &expr)
Cast an exprt to a with_exprt.
const implies_exprt & to_implies_expr(const exprt &expr)
Cast an exprt to a implies_exprt.
const update_exprt & to_update_expr(const exprt &expr)
Cast an exprt to an update_exprt.
const unary_minus_exprt & to_unary_minus_expr(const exprt &expr)
Cast an exprt to a unary_minus_exprt.
const equal_exprt & to_equal_expr(const exprt &expr)
Cast an exprt to an equal_exprt.
const nondet_symbol_exprt & to_nondet_symbol_expr(const exprt &expr)
Cast an exprt to a nondet_symbol_exprt.
const sign_exprt & to_sign_expr(const exprt &expr)
Cast an exprt to a sign_exprt.
const euclidean_mod_exprt & to_euclidean_mod_expr(const exprt &expr)
Cast an exprt to a euclidean_mod_exprt.
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
const struct_tag_typet & to_struct_tag_type(const typet &type)
Cast a typet to a struct_tag_typet.
const complex_typet & to_complex_type(const typet &type)
Cast a typet to a complex_typet.
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
std::size_t unsafe_string2size_t(const std::string &str, int base)
const string_constantt & to_string_constant(const exprt &expr)
static bool failed(bool error_indicator)