Skip to content

Commit 6071d79

Browse files
author
Joel Allred
committed
Get size from array if not available in model
If the size of the array is not provided by the model, get the size directly from the array. Note that the non-constant case now returns an empty optional rather than an unknown exprt.
1 parent c4e3eb2 commit 6071d79

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/solvers/strings/string_refinement.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,9 @@ void string_refinementt::add_lemma(
950950
}
951951

952952
/// Get a model of the size of the input string.
953+
/// First ask the solver for a size value. If the solver has no value, get the
954+
/// size directly from the type. This is the case for string literals that are
955+
/// not part of the decision procedure (e.g. literals in return values).
953956
/// If the size value is not a constant, not a valid integer (size_t), or
954957
/// greater than MAX_CONCRETE_STRING_SIZE, return no value.
955958
/// \param super_get: function returning the valuation of an expression
@@ -968,19 +971,22 @@ static optionalt<exprt> get_valid_array_size(
968971
const array_poolt &array_pool)
969972
{
970973
const auto &size_from_pool = array_pool.get_length_if_exists(arr);
971-
const exprt size = size_from_pool.has_value()
972-
? size_from_pool.value()
973-
: exprt(ID_unknown, arr.length_type());
974-
975-
exprt size_val = super_get(size);
976-
size_val = simplify_expr(size_val, ns);
977-
978-
if(size_val.id() != ID_constant)
974+
exprt size_val;
975+
if(size_from_pool.has_value())
979976
{
980-
stream << "(sr::get_valid_array_size) string of unknown size: "
981-
<< format(size_val) << messaget::eom;
982-
return {};
977+
const exprt size = size_from_pool.value();
978+
size_val = simplify_expr(super_get(size), ns);
979+
if(size_val.id() != ID_constant)
980+
{
981+
stream << "(sr::get_valid_array_size) string of unknown size: "
982+
<< format(size_val) << messaget::eom;
983+
return {};
984+
}
983985
}
986+
else if(to_array_type(arr.type()).size().id() == ID_constant)
987+
size_val = simplify_expr(to_array_type(arr.type()).size(), ns);
988+
else
989+
return {};
984990

985991
auto num_size_opt = numeric_cast<std::size_t>(size_val);
986992
if(!num_size_opt)

0 commit comments

Comments
 (0)