Skip to content

Commit db747d3

Browse files
authored
Merge pull request #4069 from tautschnig/string-solver-simplify
String refinement must not rely on input equations to be simplified
2 parents 69a3cc4 + 03025a1 commit db747d3

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
CORE
2+
test_starts_with.class
3+
--verbosity 10 --max-nondet-string-length 1000 --function test_starts_with.main --unwind 1 --no-simplify
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^\[.*assertion.1\].* line 8.* SUCCESS$
7+
^\[.*assertion.2\].* line 9.* FAILURE$
8+
--
9+
non equal types
10+
--
11+
This test must also pass when not running simplification during goto-symex
12+
(--no-simplify). Prior to the changes in this commit the test would yield wrong
13+
results for either line 8, because the string solver was not able to identify
14+
the string object in a non-simplified expression.

src/solvers/strings/string_constraint_generator_main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Author: Romain Brenguier, [email protected]
2626
#include <util/arith_tools.h>
2727
#include <util/deprecate.h>
2828
#include <util/pointer_predicates.h>
29+
#include <util/simplify_expr.h>
2930
#include <util/ssa_expr.h>
3031
#include <util/string_constant.h>
3132

@@ -180,7 +181,7 @@ exprt string_constraint_generatort::associate_array_to_pointer(
180181
: f.arguments()[0]);
181182

182183
const exprt &pointer_expr = f.arguments()[1];
183-
array_pool.insert(pointer_expr, array_expr);
184+
array_pool.insert(simplify_expr(pointer_expr, ns), array_expr);
184185
// created_strings.emplace(to_array_string_expr(array_expr));
185186
return from_integer(0, f.type());
186187
}

src/solvers/strings/string_refinement.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ static void add_equations_for_symbol_resolution(
339339

340340
if(is_char_pointer_type(rhs.type()))
341341
{
342-
symbol_solver.make_union(lhs, rhs);
342+
symbol_solver.make_union(lhs, simplify_expr(rhs, ns));
343343
}
344344
else if(rhs.id() == ID_function_application)
345345
{
@@ -439,7 +439,7 @@ static void add_string_equation_to_symbol_resolution(
439439
{
440440
if(eq.rhs().type() == string_typet())
441441
{
442-
symbol_resolve.make_union(eq.lhs(), eq.rhs());
442+
symbol_resolve.make_union(eq.lhs(), simplify_expr(eq.rhs(), ns));
443443
}
444444
else if(has_subtype(eq.lhs().type(), ID_string, ns))
445445
{
@@ -646,7 +646,10 @@ decision_proceduret::resultt string_refinementt::dec_solve()
646646
for(equal_exprt &eq : equations)
647647
{
648648
if(can_cast_expr<function_application_exprt>(eq.rhs()))
649+
{
650+
simplify(eq.rhs(), ns);
649651
string_id_symbol_resolve.replace_expr(eq.rhs());
652+
}
650653
}
651654

652655
// Generator is also used by get, so we have to use it as a class member

0 commit comments

Comments
 (0)