@@ -270,12 +270,15 @@ static void make_char_array_pointer_associations(
270
270
}
271
271
}
272
272
273
- void replace_symbols_in_equations (
274
- const union_find_replacet &symbol_resolve,
275
- std::vector<equal_exprt> &equations)
273
+ // / Substitute sub-expressions in equation by representative elements of
274
+ // / `symbol_resolve` whenever possible.
275
+ // / Similar to `symbol_resolve.replace_expr` but doesn't mutate the expression
276
+ // / and returns the transformed expression instead.
277
+ static exprt
278
+ replace_expr_copy (const union_find_replacet &symbol_resolve, exprt expr)
276
279
{
277
- for (equal_exprt &eq : equations)
278
- symbol_resolve. replace_expr (eq) ;
280
+ symbol_resolve. replace_expr (expr);
281
+ return expr ;
279
282
}
280
283
281
284
// / Record the constraints to ensure that the expression is true when
@@ -654,11 +657,15 @@ decision_proceduret::resultt string_refinementt::dec_solve()
654
657
std::vector<equal_exprt> local_equations;
655
658
for (const equal_exprt &eq : equations)
656
659
{
657
- equal_exprt eq_copy = eq;
658
- // Char array symbols are replaced by cannonical element to ensure
659
- // equal arrays are associated to the same nodes in the graph.
660
- symbol_resolve.replace_expr (eq_copy);
661
- if (!add_node (dependencies, eq_copy, generator.array_pool ))
660
+ // Ensures that arrays that are equal, are associated to the same nodes
661
+ // in the graph.
662
+ const equal_exprt eq_with_char_array_replaced_with_representative_elements =
663
+ to_equal_expr (replace_expr_copy (symbol_resolve, eq));
664
+ const bool node_added = add_node (
665
+ dependencies,
666
+ eq_with_char_array_replaced_with_representative_elements,
667
+ generator.array_pool );
668
+ if (!node_added)
662
669
local_equations.push_back (eq);
663
670
}
664
671
equations.clear ();
0 commit comments