Skip to content

Commit 682cd1a

Browse files
Use a symbol generator to avoid name clashes
In substitute_array_access, we generate an unbound symbol for each access in an empty array.
1 parent 28a2ada commit 682cd1a

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/solvers/refinement/string_refinement.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,11 +1079,16 @@ exprt fill_in_array_expr(const array_exprt &expr, std::size_t string_max_length)
10791079
/// * for an access in an empty array `{ }[x]` returns a fresh symbol, this
10801080
/// corresponds to a non-deterministic result
10811081
/// \param expr: an expression containing array accesses
1082+
/// \param symbol_generator: function which given a prefix and a type generates
1083+
/// a fresh symbol of the given type
10821084
/// \return an expression containing no array access
1083-
static void substitute_array_access(exprt &expr)
1085+
static void substitute_array_access(
1086+
exprt &expr,
1087+
const std::function<symbol_exprt(const irep_idt &, const typet &)>
1088+
&symbol_generator)
10841089
{
10851090
for(auto &op : expr.operands())
1086-
substitute_array_access(op);
1091+
substitute_array_access(op, symbol_generator);
10871092

10881093
if(expr.id()==ID_index)
10891094
{
@@ -1112,9 +1117,9 @@ static void substitute_array_access(exprt &expr)
11121117
// Substitute recursively in branches of conditional expressions
11131118
if_exprt if_expr=to_if_expr(index_expr.array());
11141119
exprt true_case=index_exprt(if_expr.true_case(), index_expr.index());
1115-
substitute_array_access(true_case);
1120+
substitute_array_access(true_case, symbol_generator);
11161121
exprt false_case=index_exprt(if_expr.false_case(), index_expr.index());
1117-
substitute_array_access(false_case);
1122+
substitute_array_access(false_case, symbol_generator);
11181123
expr=if_exprt(if_expr.cond(), true_case, false_case);
11191124
return;
11201125
}
@@ -1131,7 +1136,7 @@ static void substitute_array_access(exprt &expr)
11311136
// Access to an empty array is undefined (non deterministic result)
11321137
if(array_expr.operands().empty())
11331138
{
1134-
expr = symbol_exprt("out_of_bound_access", char_type);
1139+
expr = symbol_generator("out_of_bound_access", char_type);
11351140
return;
11361141
}
11371142

@@ -1348,6 +1353,12 @@ static std::pair<bool, std::vector<exprt>> check_axioms(
13481353
const auto eom=messaget::eom;
13491354
static const std::string indent = " ";
13501355
static const std::string indent2 = " ";
1356+
// clang-format off
1357+
const auto gen_symbol = [&](const irep_idt &id, const typet &type)
1358+
{
1359+
return generator.fresh_symbol(id, type);
1360+
};
1361+
// clang-format on
13511362

13521363
stream << "string_refinementt::check_axioms:" << eom;
13531364

@@ -1389,7 +1400,8 @@ static std::pair<bool, std::vector<exprt>> check_axioms(
13891400
negaxiom = simplify_expr(negaxiom, ns);
13901401
exprt with_concretized_arrays =
13911402
concretize_arrays_in_expression(negaxiom, max_string_length, ns);
1392-
substitute_array_access(with_concretized_arrays);
1403+
1404+
substitute_array_access(with_concretized_arrays, gen_symbol);
13931405

13941406
stream << indent << i << ".\n";
13951407
debug_check_axioms_step(
@@ -1445,7 +1457,7 @@ static std::pair<bool, std::vector<exprt>> check_axioms(
14451457
exprt with_concrete_arrays =
14461458
concretize_arrays_in_expression(negaxiom, max_string_length, ns);
14471459

1448-
substitute_array_access(with_concrete_arrays);
1460+
substitute_array_access(with_concrete_arrays, gen_symbol);
14491461

14501462
stream << indent << i << ".\n";
14511463
debug_check_axioms_step(

0 commit comments

Comments
 (0)