Skip to content

Commit b737ba2

Browse files
committed
String refinement must not rely on input equations to be simplified
JBMC would produce wrong results when running the newly added test. Various methods in string solver either assume a canonical representation of objects in table lookups or only deal with a limited set of expressions, which is reasonable so as not to duplicate abilities that the simplifier already has.
1 parent 6eaff21 commit b737ba2

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
@@ -338,7 +338,7 @@ static void add_equations_for_symbol_resolution(
338338

339339
if(is_char_pointer_type(rhs.type()))
340340
{
341-
symbol_solver.make_union(lhs, rhs);
341+
symbol_solver.make_union(lhs, simplify_expr(rhs, ns));
342342
}
343343
else if(rhs.id() == ID_function_application)
344344
{
@@ -438,7 +438,7 @@ static void add_string_equation_to_symbol_resolution(
438438
{
439439
if(eq.rhs().type() == string_typet())
440440
{
441-
symbol_resolve.make_union(eq.lhs(), eq.rhs());
441+
symbol_resolve.make_union(eq.lhs(), simplify_expr(eq.rhs(), ns));
442442
}
443443
else if(has_subtype(eq.lhs().type(), ID_string, ns))
444444
{
@@ -645,7 +645,10 @@ decision_proceduret::resultt string_refinementt::dec_solve()
645645
for(equal_exprt &eq : equations)
646646
{
647647
if(can_cast_expr<function_application_exprt>(eq.rhs()))
648+
{
649+
simplify(eq.rhs(), ns);
648650
string_id_symbol_resolve.replace_expr(eq.rhs());
651+
}
649652
}
650653

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

0 commit comments

Comments
 (0)