Skip to content

Commit 28a2ada

Browse files
Access in empty array should be unconstrained
We make the result non-deterministic by introducing a new symbol
1 parent d41403f commit 28a2ada

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/solvers/refinement/string_refinement.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,8 @@ exprt fill_in_array_expr(const array_exprt &expr, std::size_t string_max_length)
10761076
/// expression will be: `index==0 ? 24 : index==2 ? 42 : 12`
10771077
/// * for an array access `(g1?arr1:arr2)[x]` where `arr1 := {12}` and
10781078
/// `arr2 := {34}`, the constructed expression will be: `g1 ? 12 : 34`
1079+
/// * for an access in an empty array `{ }[x]` returns a fresh symbol, this
1080+
/// corresponds to a non-deterministic result
10791081
/// \param expr: an expression containing array accesses
10801082
/// \return an expression containing no array access
10811083
static void substitute_array_access(exprt &expr)
@@ -1124,13 +1126,17 @@ static void substitute_array_access(exprt &expr)
11241126
"above"));
11251127
array_exprt &array_expr=to_array_expr(index_expr.array());
11261128

1127-
// Empty arrays do not need to be substituted.
1129+
const typet &char_type = index_expr.array().type().subtype();
1130+
1131+
// Access to an empty array is undefined (non deterministic result)
11281132
if(array_expr.operands().empty())
1133+
{
1134+
expr = symbol_exprt("out_of_bound_access", char_type);
11291135
return;
1136+
}
11301137

11311138
size_t last_index=array_expr.operands().size()-1;
11321139

1133-
const typet &char_type=index_expr.array().type().subtype();
11341140
exprt ite=array_expr.operands().back();
11351141

11361142
if(ite.type()!=char_type)

0 commit comments

Comments
 (0)