@@ -950,6 +950,9 @@ void string_refinementt::add_lemma(
950
950
}
951
951
952
952
// / 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).
953
956
// / If the size value is not a constant, not a valid integer (size_t), or
954
957
// / greater than MAX_CONCRETE_STRING_SIZE, return no value.
955
958
// / \param super_get: function returning the valuation of an expression
@@ -968,19 +971,22 @@ static optionalt<exprt> get_valid_array_size(
968
971
const array_poolt &array_pool)
969
972
{
970
973
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 ())
979
976
{
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
+ }
983
985
}
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 {};
984
990
985
991
auto num_size_opt = numeric_cast<std::size_t >(size_val);
986
992
if (!num_size_opt)
0 commit comments