Skip to content

Commit beff419

Browse files
Use sparse arrays in get_array
This ensures that arrays from the underlying solver are interpreted in a consistent manner in the solver (always using interval_sparse_arrayt).
1 parent 9b286d9 commit beff419

File tree

2 files changed

+15
-42
lines changed

2 files changed

+15
-42
lines changed

src/solvers/refinement/string_refinement.cpp

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -935,50 +935,21 @@ static optionalt<exprt> get_array(
935935
}
936936
std::size_t n = *n_opt;
937937

938-
const array_typet ret_type(char_type, from_integer(n, index_type));
939-
array_exprt ret(ret_type);
940-
941-
if(n>max_string_length)
938+
if(n > MAX_CONCRETE_STRING_SIZE)
942939
{
943940
stream << "(sr::get_array) long string (size=" << n << ")" << eom;
944-
return {};
945-
}
946-
947-
if(n==0)
948-
return empty_ret;
949-
950-
if(arr_val.id()=="array-list")
951-
{
952-
DATA_INVARIANT(
953-
arr_val.operands().size()%2==0,
954-
string_refinement_invariantt("and index expression must be on a symbol, "
955-
"with, array_of, if, or array, and all "
956-
"cases besides array are handled above"));
957-
std::map<std::size_t, exprt> initial_map;
958-
for(size_t i = 0; i < arr_val.operands().size(); i += 2)
959-
{
960-
exprt index = arr_val.operands()[i];
961-
if(auto idx = numeric_cast<std::size_t>(index))
962-
{
963-
if(*idx < n)
964-
initial_map[*idx] = arr_val.operands()[i + 1];
965-
}
966-
}
967-
968-
// Pad the concretized values to the left to assign the uninitialized
969-
// values of result.
970-
ret.operands()=fill_in_map_as_vector(initial_map);
971-
return ret;
972-
}
973-
else if(arr_val.id()==ID_array)
974-
{
975-
// copy the `n` first elements of `arr_val`
976-
for(size_t i=0; i<arr_val.operands().size() && i<n; i++)
977-
ret.move_to_operands(arr_val.operands()[i]);
978-
return ret;
979-
}
980-
else
981-
return {};
941+
std::ostringstream msg;
942+
msg << "consider reducing string-max-input-length so that no string "
943+
<< "exceeds " << MAX_CONCRETE_STRING_SIZE << " in length and make sure"
944+
<< " all functions returning strings are available in the classpath";
945+
throw string_refinement_invariantt(msg.str());
946+
}
947+
948+
if(
949+
const auto &array = interval_sparse_arrayt::of_expr(
950+
arr_val, from_integer(CHARACTER_FOR_UNKNOWN, char_type)))
951+
return array->concretize(n, index_type);
952+
return {};
982953
}
983954

984955
/// convert the content of a string to a more readable representation. This

src/solvers/refinement/string_refinement.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Author: Alberto Griggio, [email protected]
3131

3232
#define DEFAULT_MAX_NB_REFINEMENT std::numeric_limits<size_t>::max()
3333
#define CHARACTER_FOR_UNKNOWN '?'
34+
// Limit the size of strings in traces to 64M chars to avoid memout
35+
#define MAX_CONCRETE_STRING_SIZE (1 << 26)
3436

3537
class string_refinementt final: public bv_refinementt
3638
{

0 commit comments

Comments
 (0)