@@ -951,16 +951,18 @@ void string_refinementt::add_lemma(
951
951
prop.l_set_to_true (convert (simple_lemma));
952
952
}
953
953
954
- // / Get a model of an array and put it in a certain form.
955
- // / If the model is incomplete or if it is too big, return no value.
954
+ // / Get a model of the size of the input string.
955
+ // / If the size value is not a constant or not a valid integer (size_t),
956
+ // / return no value.
956
957
// / \param super_get: function returning the valuation of an expression
957
958
// / in a model
958
959
// / \param ns: namespace
959
960
// / \param stream: output stream for warning messages
960
961
// / \param arr: expression of type array representing a string
961
962
// / \param array_pool: pool of arrays representing strings
962
- // / \return an optional array expression or array_of_exprt
963
- static optionalt<exprt> get_array (
963
+ // / \return an optional expression representing the size of the array that can
964
+ // / be cast to size_t
965
+ static optionalt<exprt> get_valid_array_size (
964
966
const std::function<exprt(const exprt &)> &super_get,
965
967
const namespacet &ns,
966
968
messaget::mstreamt &stream,
@@ -972,42 +974,73 @@ static optionalt<exprt> get_array(
972
974
? size_from_pool.value ()
973
975
: exprt (ID_unknown, arr.length_type ());
974
976
975
- exprt arr_val = simplify_expr (adjust_if_recursive (super_get (arr), ns), ns);
976
977
exprt size_val = super_get (size);
977
978
size_val = simplify_expr (size_val, ns);
978
- const typet char_type = arr.type ().subtype ();
979
- const typet &index_type = size.type ();
980
979
981
980
if (size_val.id () != ID_constant)
982
981
{
983
- stream << " (sr::get_array ) string of unknown size: " << format (size_val)
984
- << messaget::eom;
982
+ stream << " (sr::get_valid_array_size ) string of unknown size: "
983
+ << format (size_val) << messaget::eom;
985
984
return {};
986
985
}
987
986
988
987
auto n_opt = numeric_cast<std::size_t >(size_val);
989
988
if (!n_opt)
990
989
{
991
- stream << " (sr::get_array) size is not valid" << messaget::eom;
990
+ stream << " (sr::get_valid_array_size) size is not valid" << messaget::eom;
991
+ return {};
992
+ }
993
+
994
+ return size_val;
995
+ }
996
+
997
+ // / Get a model of an array and put it in a certain form.
998
+ // / If the model is incomplete or if it is too big, return no value.
999
+ // / \param super_get: function returning the valuation of an expression
1000
+ // / in a model
1001
+ // / \param ns: namespace
1002
+ // / \param stream: output stream for warning messages
1003
+ // / \param arr: expression of type array representing a string
1004
+ // / \param array_pool: pool of arrays representing strings
1005
+ // / \return an optional array expression or array_of_exprt
1006
+ static optionalt<exprt> get_array (
1007
+ const std::function<exprt(const exprt &)> &super_get,
1008
+ const namespacet &ns,
1009
+ messaget::mstreamt &stream,
1010
+ const array_string_exprt &arr,
1011
+ const array_poolt &array_pool)
1012
+ {
1013
+ const auto size =
1014
+ get_valid_array_size (super_get, ns, stream, arr, array_pool);
1015
+ if (!size.has_value ())
1016
+ {
992
1017
return {};
993
1018
}
994
- std::size_t n = *n_opt;
1019
+
1020
+ const size_t n = numeric_cast<std::size_t >(size.value ()).value ();
995
1021
996
1022
if (n > MAX_CONCRETE_STRING_SIZE)
997
1023
{
998
- stream << " (sr::get_array) long string (size = " << n << " ) " << format (arr)
999
- << messaget::eom;
1000
- stream << " (sr::get_array) consider reducing max-nondet-string-length so "
1024
+ stream << " (sr::get_valid_array_size) long string (size "
1025
+ << " = " << n << " ) " << format (arr) << messaget::eom;
1026
+ stream << " (sr::get_valid_array_size) consider reducing "
1027
+ " max-nondet-string-length so "
1001
1028
" that no string exceeds "
1002
1029
<< MAX_CONCRETE_STRING_SIZE
1003
1030
<< " in length and "
1004
1031
" make sure all functions returning strings are loaded"
1005
1032
<< messaget::eom;
1006
- stream << " (sr::get_array) this can also happen on invalid object access"
1033
+ stream << " (sr::get_valid_array_size) this can also happen on invalid "
1034
+ " object access"
1007
1035
<< messaget::eom;
1008
1036
return nil_exprt ();
1009
1037
}
1010
1038
1039
+ const exprt arr_val =
1040
+ simplify_expr (adjust_if_recursive (super_get (arr), ns), ns);
1041
+ const typet char_type = arr.type ().subtype ();
1042
+ const typet &index_type = size.value ().type ();
1043
+
1011
1044
if (
1012
1045
const auto &array = interval_sparse_arrayt::of_expr (
1013
1046
arr_val, from_integer (CHARACTER_FOR_UNKNOWN, char_type)))
0 commit comments