Skip to content

Commit 8b7f2bd

Browse files
committed
Field sensitivity: do not simplify unconditionally
The option --no-simplify should be honoured by field sensitivity. This also made apparent that we have tests that only pass thanks to the simplifier, and perhaps aren't even expected to pass. See #6101 for further discussion.
1 parent 09b65e2 commit 8b7f2bd

11 files changed

+57
-21
lines changed
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
CORE broken-smt-backend
1+
KNOWNBUG broken-smt-backend
22
main.c
33
--no-simplify
44
^VERIFICATION SUCCESSFUL$
55
^EXIT=0$
66
^SIGNAL=0$
77
--
88
^warning: ignoring
9+
--
10+
See #6101 for a discussion as to whether this should be supported at all.
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
CORE broken-smt-backend
1+
KNOWNBUG broken-smt-backend
22
main.c
33
--no-simplify
44
^VERIFICATION SUCCESSFUL$
55
^EXIT=0$
66
^SIGNAL=0$
77
--
88
^warning: ignoring
9+
--
10+
See #6101 for a discussion as to whether this should be supported at all.

src/goto-symex/field_sensitivity.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ exprt field_sensitivityt::apply(
5252
!write && expr.id() == ID_member &&
5353
to_member_expr(expr).struct_op().id() == ID_struct)
5454
{
55-
return simplify_expr(std::move(expr), ns);
55+
return simplify_opt(std::move(expr), ns);
5656
}
5757
#ifdef ENABLE_ARRAY_FIELD_SENSITIVITY
5858
else if(
5959
!write && expr.id() == ID_index &&
6060
to_index_expr(expr).array().id() == ID_array)
6161
{
62-
return simplify_expr(std::move(expr), ns);
62+
return simplify_opt(std::move(expr), ns);
6363
}
6464
#endif // ENABLE_ARRAY_FIELD_SENSITIVITY
6565
else if(expr.id() == ID_member)
@@ -95,7 +95,8 @@ exprt field_sensitivityt::apply(
9595
// encoding the index access into an array as an individual symbol rather
9696
// than only the full array
9797
index_exprt &index = to_index_expr(expr);
98-
simplify(index.index(), ns);
98+
if(should_simplify)
99+
simplify(index.index(), ns);
99100

100101
if(
101102
is_ssa_expr(index.array()) && index.array().type().id() == ID_array &&
@@ -105,7 +106,8 @@ exprt field_sensitivityt::apply(
105106
// SSA expression
106107
ssa_exprt tmp = to_ssa_expr(index.array());
107108
auto l2_index = state.rename(index.index(), ns);
108-
l2_index.simplify(ns);
109+
if(should_simplify)
110+
l2_index.simplify(ns);
109111
bool was_l2 = !tmp.get_level_2().empty();
110112
exprt l2_size =
111113
state.rename(to_array_type(index.array().type()).size(), ns).get();
@@ -262,7 +264,8 @@ void field_sensitivityt::field_assignments_rec(
262264
else if(is_ssa_expr(lhs_fs))
263265
{
264266
exprt ssa_rhs = state.rename(lhs, ns).get();
265-
simplify(ssa_rhs, ns);
267+
if(should_simplify)
268+
simplify(ssa_rhs, ns);
266269

267270
const ssa_exprt ssa_lhs = state
268271
.assignment(
@@ -363,3 +366,11 @@ bool field_sensitivityt::is_divisible(const ssa_exprt &expr) const
363366

364367
return false;
365368
}
369+
370+
exprt field_sensitivityt::simplify_opt(exprt e, const namespacet &ns) const
371+
{
372+
if(!should_simplify)
373+
return e;
374+
375+
return simplify_expr(std::move(e), ns);
376+
}

src/goto-symex/field_sensitivity.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,10 @@ class field_sensitivityt
8484
public:
8585
/// \param max_array_size: maximum size for which field sensitivity will be
8686
/// applied to array cells
87-
explicit field_sensitivityt(std::size_t max_array_size)
88-
: max_field_sensitivity_array_size(max_array_size)
87+
/// \param should_simplify: simplify expressions
88+
field_sensitivityt(std::size_t max_array_size, bool should_simplify)
89+
: max_field_sensitivity_array_size(max_array_size),
90+
should_simplify(should_simplify)
8991
{
9092
}
9193

@@ -157,13 +159,17 @@ class field_sensitivityt
157159

158160
const std::size_t max_field_sensitivity_array_size;
159161

162+
const bool should_simplify;
163+
160164
void field_assignments_rec(
161165
const namespacet &ns,
162166
goto_symex_statet &state,
163167
const exprt &lhs_fs,
164168
const exprt &lhs,
165169
symex_targett &target,
166170
bool allow_pointer_unsoundness);
171+
172+
exprt simplify_opt(exprt e, const namespacet &ns) const;
167173
};
168174

169175
#endif // CPROVER_GOTO_SYMEX_FIELD_SENSITIVITY_H

src/goto-symex/goto_symex_state.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ static void get_l1_name(exprt &expr);
3131
goto_symex_statet::goto_symex_statet(
3232
const symex_targett::sourcet &_source,
3333
std::size_t max_field_sensitive_array_size,
34+
bool should_simplify,
3435
guard_managert &manager,
3536
std::function<std::size_t(const irep_idt &)> fresh_l2_name_provider)
3637
: goto_statet(manager),
3738
source(_source),
3839
guard_manager(manager),
3940
symex_target(nullptr),
40-
field_sensitivity(max_field_sensitive_array_size),
41+
field_sensitivity(max_field_sensitive_array_size, should_simplify),
4142
record_events({true}),
4243
fresh_l2_name_provider(fresh_l2_name_provider)
4344
{

src/goto-symex/goto_symex_state.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class goto_symex_statet final : public goto_statet
4444
goto_symex_statet(
4545
const symex_targett::sourcet &,
4646
std::size_t max_field_sensitive_array_size,
47+
bool should_simplify,
4748
guard_managert &manager,
4849
std::function<std::size_t(const irep_idt &)> fresh_l2_name_provider);
4950
~goto_symex_statet();

src/goto-symex/symex_main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ std::unique_ptr<goto_symext::statet> goto_symext::initialize_entry_point_state(
422422
auto state = util_make_unique<statet>(
423423
symex_targett::sourcet(entry_point_id, start_function->body),
424424
symex_config.max_field_sensitivity_array_size,
425+
symex_config.simplify_opt,
425426
guard_manager,
426427
[storage](const irep_idt &id) { return storage->get_unique_l2_index(id); });
427428

unit/goto-symex/apply_condition.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@ SCENARIO(
4444
guard_managert guard_manager;
4545
std::size_t count = 0;
4646
auto fresh_name = [&count](const irep_idt &) { return count++; };
47-
goto_symex_statet state{source,
48-
DEFAULT_MAX_FIELD_SENSITIVITY_ARRAY_SIZE,
49-
guard_manager,
50-
fresh_name};
47+
goto_symex_statet state{
48+
source,
49+
DEFAULT_MAX_FIELD_SENSITIVITY_ARRAY_SIZE,
50+
true,
51+
guard_manager,
52+
fresh_name};
5153

5254
goto_statet goto_state{state};
5355
const exprt renamed_b = state.rename<L2>(b, ns).get();

unit/goto-symex/goto_symex_state.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ SCENARIO(
4040
return fresh_name_count++;
4141
};
4242
goto_symex_statet state{
43-
source, DEFAULT_MAX_FIELD_SENSITIVITY_ARRAY_SIZE, manager, fresh_name};
43+
source,
44+
DEFAULT_MAX_FIELD_SENSITIVITY_ARRAY_SIZE,
45+
true,
46+
manager,
47+
fresh_name};
4448

4549
// Initialize dirty field of state
4650
incremental_dirtyt dirty;

unit/goto-symex/symex_assign.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ SCENARIO(
5151
return fresh_name_count++;
5252
};
5353
goto_symex_statet state{
54-
source, DEFAULT_MAX_FIELD_SENSITIVITY_ARRAY_SIZE, manager, fresh_name};
54+
source,
55+
DEFAULT_MAX_FIELD_SENSITIVITY_ARRAY_SIZE,
56+
true,
57+
manager,
58+
fresh_name};
5559

5660
// Initialize dirty field of state
5761
incremental_dirtyt dirty;

unit/goto-symex/try_evaluate_pointer_comparisons.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@ SCENARIO(
5454
guard_managert guard_manager;
5555
std::size_t count = 0;
5656
auto fresh_name = [&count](const irep_idt &) { return count++; };
57-
goto_symex_statet state{source,
58-
DEFAULT_MAX_FIELD_SENSITIVITY_ARRAY_SIZE,
59-
guard_manager,
60-
fresh_name};
57+
goto_symex_statet state{
58+
source,
59+
DEFAULT_MAX_FIELD_SENSITIVITY_ARRAY_SIZE,
60+
true,
61+
guard_manager,
62+
fresh_name};
6163

6264
GIVEN("A value set in which pointer symbol `ptr1` only points to `&value1`")
6365
{
@@ -249,7 +251,7 @@ SCENARIO(
249251
// struct_symbol..pointer_field <- &value1
250252
{
251253
field_sensitivityt field_sensitivity{
252-
DEFAULT_MAX_FIELD_SENSITIVITY_ARRAY_SIZE};
254+
DEFAULT_MAX_FIELD_SENSITIVITY_ARRAY_SIZE, true};
253255
const exprt index_fs =
254256
field_sensitivity.apply(ns, state, member_l1.get(), true);
255257
value_set.assign(index_fs, address1_l1.get(), ns, false, false);

0 commit comments

Comments
 (0)