Skip to content

Commit 7678ef1

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 536253b commit 7678ef1

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
@@ -952,6 +952,9 @@ void string_refinementt::add_lemma(
952952
}
953953

954954
/// Get a model of the size of the input string.
955+
/// First ask the solver for a size value. If the solver has no value, get the
956+
/// size directly from the type. This is the case for string literals that are
957+
/// not part of the decision procedure (e.g. literals in return values).
955958
/// If the size value is not a constant or not a valid integer (size_t),
956959
/// return no value.
957960
/// \param super_get: function returning the valuation of an expression
@@ -970,19 +973,22 @@ static optionalt<exprt> get_valid_array_size(
970973
const array_poolt &array_pool)
971974
{
972975
const auto &size_from_pool = array_pool.get_length_if_exists(arr);
973-
const exprt size = size_from_pool.has_value()
974-
? size_from_pool.value()
975-
: exprt(ID_unknown, arr.length_type());
976-
977-
exprt size_val = super_get(size);
978-
size_val = simplify_expr(size_val, ns);
979-
980-
if(size_val.id() != ID_constant)
976+
exprt size_val;
977+
if(size_from_pool.has_value())
981978
{
982-
stream << "(sr::get_valid_array_size) string of unknown size: "
983-
<< format(size_val) << messaget::eom;
984-
return {};
979+
const exprt size = size_from_pool.value();
980+
size_val = simplify_expr(super_get(size), ns);
981+
if(size_val.id() != ID_constant)
982+
{
983+
stream << "(sr::get_valid_array_size) string of unknown size: "
984+
<< format(size_val) << messaget::eom;
985+
return {};
986+
}
985987
}
988+
else if(to_array_type(arr.type()).size().id() == ID_constant)
989+
size_val = simplify_expr(to_array_type(arr.type()).size(), ns);
990+
else
991+
return {};
986992

987993
auto n_opt = numeric_cast<std::size_t>(size_val);
988994
if(!n_opt)

0 commit comments

Comments
 (0)