Skip to content

Commit 4b88740

Browse files
committed
Use simplify_expr_with_value_sett across goto-symex
value-set based simplifications may be helpful well outside just GOTO conditions.
1 parent fc80921 commit 4b88740

21 files changed

+154
-77
lines changed

src/goto-symex/field_sensitivity.cpp

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ Author: Michael Tautschnig
1212
#include <util/byte_operators.h>
1313
#include <util/c_types.h>
1414
#include <util/pointer_offset_size.h>
15-
#include <util/simplify_expr.h>
1615

1716
#include "goto_symex_state.h"
17+
#include "simplify_expr_with_value_set.h"
1818
#include "symex_target.h"
1919

2020
#define ENABLE_ARRAY_FIELD_SENSITIVITY
@@ -51,14 +51,14 @@ exprt field_sensitivityt::apply(
5151
!write && expr.id() == ID_member &&
5252
to_member_expr(expr).struct_op().id() == ID_struct)
5353
{
54-
return simplify_opt(std::move(expr), ns);
54+
return simplify_opt(std::move(expr), state.value_set, ns);
5555
}
5656
#ifdef ENABLE_ARRAY_FIELD_SENSITIVITY
5757
else if(
5858
!write && expr.id() == ID_index &&
5959
to_index_expr(expr).array().id() == ID_array)
6060
{
61-
return simplify_opt(std::move(expr), ns);
61+
return simplify_opt(std::move(expr), state.value_set, ns);
6262
}
6363
#endif // ENABLE_ARRAY_FIELD_SENSITIVITY
6464
else if(expr.id() == ID_member)
@@ -151,7 +151,10 @@ exprt field_sensitivityt::apply(
151151
// than only the full array
152152
index_exprt &index = to_index_expr(expr);
153153
if(should_simplify)
154-
simplify(index.index(), ns);
154+
{
155+
simplify_expr_with_value_sett{state.value_set, language_mode, ns}
156+
.simplify(index.index());
157+
}
155158

156159
if(
157160
is_ssa_expr(index.array()) && index.array().type().id() == ID_array &&
@@ -162,7 +165,10 @@ exprt field_sensitivityt::apply(
162165
ssa_exprt tmp = to_ssa_expr(index.array());
163166
auto l2_index = state.rename(index.index(), ns).get();
164167
if(should_simplify)
165-
simplify(l2_index, ns);
168+
{
169+
simplify_expr_with_value_sett{state.value_set, language_mode, ns}
170+
.simplify(l2_index);
171+
}
166172
bool was_l2 = !tmp.get_level_2().empty();
167173
exprt l2_size =
168174
state.rename(to_array_type(index.array().type()).size(), ns).get();
@@ -393,7 +399,10 @@ void field_sensitivityt::field_assignments_rec(
393399
const exprt member_rhs = apply(
394400
ns,
395401
state,
396-
simplify_opt(member_exprt{ssa_rhs, comp.get_name(), comp.type()}, ns),
402+
simplify_opt(
403+
member_exprt{ssa_rhs, comp.get_name(), comp.type()},
404+
state.value_set,
405+
ns),
397406
false);
398407

399408
const exprt &member_lhs = *fs_it;
@@ -437,6 +446,7 @@ void field_sensitivityt::field_assignments_rec(
437446
simplify_opt(
438447
make_byte_extract(
439448
ssa_rhs, from_integer(0, c_index_type()), comp.type()),
449+
state.value_set,
440450
ns),
441451
false);
442452

@@ -476,7 +486,9 @@ void field_sensitivityt::field_assignments_rec(
476486
ns,
477487
state,
478488
simplify_opt(
479-
index_exprt{ssa_rhs, from_integer(i, type->index_type())}, ns),
489+
index_exprt{ssa_rhs, from_integer(i, type->index_type())},
490+
state.value_set,
491+
ns),
480492
false);
481493

482494
const exprt &index_lhs = *fs_it;
@@ -558,10 +570,14 @@ bool field_sensitivityt::is_divisible(
558570
return false;
559571
}
560572

561-
exprt field_sensitivityt::simplify_opt(exprt e, const namespacet &ns) const
573+
exprt field_sensitivityt::simplify_opt(
574+
exprt e,
575+
const value_sett &value_set,
576+
const namespacet &ns) const
562577
{
563578
if(!should_simplify)
564579
return e;
565580

566-
return simplify_expr(std::move(e), ns);
581+
simplify_expr_with_value_sett{value_set, language_mode, ns}.simplify(e);
582+
return e;
567583
}

src/goto-symex/field_sensitivity.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Author: Michael Tautschnig
1414
class namespacet;
1515
class goto_symex_statet;
1616
class symex_targett;
17+
class value_sett;
1718

1819
class field_sensitive_ssa_exprt : public exprt
1920
{
@@ -119,9 +120,14 @@ class field_sensitivityt
119120
/// \param max_array_size: maximum size for which field sensitivity will be
120121
/// applied to array cells
121122
/// \param should_simplify: simplify expressions
122-
field_sensitivityt(std::size_t max_array_size, bool should_simplify)
123+
/// \param language_mode: mode of the language that expressions belong to.
124+
field_sensitivityt(
125+
std::size_t max_array_size,
126+
bool should_simplify,
127+
const irep_idt &language_mode)
123128
: max_field_sensitivity_array_size(max_array_size),
124-
should_simplify(should_simplify)
129+
should_simplify(should_simplify),
130+
language_mode(language_mode)
125131
{
126132
}
127133

@@ -201,6 +207,7 @@ class field_sensitivityt
201207
const std::size_t max_field_sensitivity_array_size;
202208

203209
const bool should_simplify;
210+
const irep_idt &language_mode;
204211

205212
void field_assignments_rec(
206213
const namespacet &ns,
@@ -210,7 +217,10 @@ class field_sensitivityt
210217
symex_targett &target,
211218
bool allow_pointer_unsoundness) const;
212219

213-
[[nodiscard]] exprt simplify_opt(exprt e, const namespacet &ns) const;
220+
[[nodiscard]] exprt simplify_opt(
221+
exprt e,
222+
const value_sett &value_set,
223+
const namespacet &ns) const;
214224
};
215225

216226
#endif // CPROVER_GOTO_SYMEX_FIELD_SENSITIVITY_H

src/goto-symex/goto_symex.cpp

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,30 @@ Author: Daniel Kroening, [email protected]
1111

1212
#include "goto_symex.h"
1313

14-
#include "expr_skeleton.h"
15-
#include "symex_assign.h"
16-
1714
#include <util/arith_tools.h>
1815
#include <util/c_types.h>
1916
#include <util/format_expr.h>
2017
#include <util/fresh_symbol.h>
2118
#include <util/mathematical_expr.h>
2219
#include <util/mathematical_types.h>
2320
#include <util/pointer_offset_size.h>
24-
#include <util/simplify_expr.h>
2521
#include <util/simplify_utils.h>
2622
#include <util/std_code.h>
2723
#include <util/string_expr.h>
2824
#include <util/string_utils.h>
2925

26+
#include "expr_skeleton.h"
27+
#include "simplify_expr_with_value_set.h"
28+
#include "symex_assign.h"
29+
3030
#include <climits>
3131

32-
void goto_symext::do_simplify(exprt &expr)
32+
void goto_symext::do_simplify(exprt &expr, const value_sett &value_set)
3333
{
3434
if(symex_config.simplify_opt)
35-
simplify(expr, ns);
35+
{
36+
simplify_expr_with_value_sett{value_set, language_mode, ns}.simplify(expr);
37+
}
3638
}
3739

3840
void goto_symext::symex_assign(
@@ -61,7 +63,7 @@ void goto_symext::symex_assign(
6163
// "byte_extract <type> from an_lvalue offset this_rvalue") can affect whether
6264
// we use field-sensitive symbols or not, so L2-rename them up front:
6365
lhs = state.l2_rename_rvalues(lhs, ns);
64-
do_simplify(lhs);
66+
do_simplify(lhs, state.value_set);
6567
lhs = state.field_sensitivity.apply(ns, state, std::move(lhs), true);
6668

6769
if(rhs.id() == ID_side_effect)
@@ -104,7 +106,13 @@ void goto_symext::symex_assign(
104106
assignment_type = symex_targett::assignment_typet::HIDDEN;
105107

106108
symex_assignt symex_assign{
107-
shadow_memory, state, assignment_type, ns, symex_config, target};
109+
shadow_memory,
110+
state,
111+
assignment_type,
112+
ns,
113+
symex_config,
114+
language_mode,
115+
target};
108116

109117
// Try to constant propagate potential side effects of the assignment, when
110118
// simplification is turned on and there is one thread only. Constant
@@ -134,7 +142,13 @@ void goto_symext::symex_assign(
134142

135143
exprt::operandst lhs_if_then_else_conditions;
136144
symex_assignt{
137-
shadow_memory, state, assignment_type, ns, symex_config, target}
145+
shadow_memory,
146+
state,
147+
assignment_type,
148+
ns,
149+
symex_config,
150+
language_mode,
151+
target}
138152
.assign_rec(lhs, expr_skeletont{}, rhs, lhs_if_then_else_conditions);
139153

140154
if(need_atomic_section)

src/goto-symex/goto_symex.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class shadow_memory_field_definitionst;
2727
class side_effect_exprt;
2828
class symex_assignt;
2929
class typet;
30+
class value_sett;
3031

3132
/// \brief The main class for the forward symbolic simulator
3233
/// \remarks
@@ -528,7 +529,7 @@ class goto_symext
528529
/// \param state: Symbolic execution state for current instruction
529530
void symex_catch(statet &state);
530531

531-
virtual void do_simplify(exprt &expr);
532+
virtual void do_simplify(exprt &expr, const value_sett &value_set);
532533

533534
/// Symbolically execute an ASSIGN instruction or simulate such an execution
534535
/// for a synthetic assignment

src/goto-symex/goto_symex_state.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ Author: Daniel Kroening, [email protected]
1818
#include <util/exception_utils.h>
1919
#include <util/expr_util.h>
2020
#include <util/invariant.h>
21-
#include <util/simplify_expr.h>
2221
#include <util/std_expr.h>
2322

2423
#include <analyses/dirty.h>
2524
#include <pointer-analysis/add_failed_symbols.h>
2625

2726
#include "goto_symex_can_forward_propagate.h"
27+
#include "simplify_expr_with_value_set.h"
2828
#include "symex_target_equation.h"
2929

3030
static void get_l1_name(exprt &expr);
@@ -33,14 +33,19 @@ goto_symex_statet::goto_symex_statet(
3333
const symex_targett::sourcet &_source,
3434
std::size_t max_field_sensitive_array_size,
3535
bool should_simplify,
36+
const irep_idt &language_mode,
3637
guard_managert &manager,
3738
std::function<std::size_t(const irep_idt &)> fresh_l2_name_provider)
3839
: goto_statet(manager),
3940
source(_source),
4041
guard_manager(manager),
4142
symex_target(nullptr),
42-
field_sensitivity(max_field_sensitive_array_size, should_simplify),
43+
field_sensitivity(
44+
max_field_sensitive_array_size,
45+
should_simplify,
46+
language_mode),
4347
record_events({true}),
48+
language_mode(language_mode),
4449
fresh_l2_name_provider(fresh_l2_name_provider)
4550
{
4651
threads.emplace_back(guard_manager);
@@ -86,7 +91,7 @@ renamedt<ssa_exprt, L2> goto_symex_statet::assignment(
8691
// the type might need renaming
8792
rename<L2>(lhs.type(), l1_identifier, ns);
8893
if(rhs_is_simplified)
89-
simplify(lhs, ns);
94+
simplify_expr_with_value_sett{value_set, language_mode, ns}.simplify(lhs);
9095
lhs.update_type();
9196
if(run_validation_checks)
9297
{

src/goto-symex/goto_symex_state.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class goto_symex_statet final : public goto_statet
4545
const symex_targett::sourcet &,
4646
std::size_t max_field_sensitive_array_size,
4747
bool should_simplify,
48+
const irep_idt &language_mode,
4849
guard_managert &manager,
4950
std::function<std::size_t(const irep_idt &)> fresh_l2_name_provider);
5051
~goto_symex_statet();
@@ -258,6 +259,7 @@ class goto_symex_statet final : public goto_statet
258259
}
259260

260261
private:
262+
const irep_idt &language_mode;
261263
std::function<std::size_t(const irep_idt &)> fresh_l2_name_provider;
262264

263265
/// \brief Dangerous, do not use

src/goto-symex/symex_assign.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ Author: Daniel Kroening, [email protected]
1515
#include <util/expr_util.h>
1616
#include <util/pointer_expr.h>
1717
#include <util/range.h>
18-
#include <util/simplify_expr.h>
1918

2019
#include "expr_skeleton.h"
2120
#include "goto_symex_state.h"
21+
#include "simplify_expr_with_value_set.h"
2222
#include "symex_config.h"
2323

2424
// We can either use with_exprt or update_exprt when building expressions that
@@ -207,7 +207,10 @@ void symex_assignt::assign_non_struct_symbol(
207207
assignmentt assignment{lhs, full_lhs, l2_rhs};
208208

209209
if(symex_config.simplify_opt)
210-
assignment.rhs = simplify_expr(std::move(assignment.rhs), ns);
210+
{
211+
simplify_expr_with_value_sett{state.value_set, language_mode, ns}.simplify(
212+
assignment.rhs);
213+
}
211214

212215
const ssa_exprt l2_lhs = state
213216
.assignment(

src/goto-symex/symex_assign.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ class symex_assignt
3333
symex_targett::assignment_typet assignment_type,
3434
const namespacet &ns,
3535
const symex_configt &symex_config,
36+
const irep_idt &language_mode,
3637
symex_targett &target)
3738
: shadow_memory(shadow_memory),
3839
state(state),
3940
assignment_type(assignment_type),
4041
ns(ns),
4142
symex_config(symex_config),
43+
language_mode(language_mode),
4244
target(target)
4345
{
4446
}
@@ -65,6 +67,7 @@ class symex_assignt
6567
symex_targett::assignment_typet assignment_type;
6668
const namespacet &ns;
6769
const symex_configt &symex_config;
70+
const irep_idt &language_mode;
6871
symex_targett &target;
6972

7073
void assign_from_struct(

src/goto-symex/symex_atomic_section.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void goto_symext::symex_atomic_end(statet &state)
5858
++it)
5959
read_guard|=*it;
6060
exprt read_guard_expr=read_guard.as_expr();
61-
do_simplify(read_guard_expr);
61+
do_simplify(read_guard_expr, state.value_set);
6262

6363
target.shared_read(
6464
read_guard_expr,
@@ -80,7 +80,7 @@ void goto_symext::symex_atomic_end(statet &state)
8080
++it)
8181
write_guard|=*it;
8282
exprt write_guard_expr=write_guard.as_expr();
83-
do_simplify(write_guard_expr);
83+
do_simplify(write_guard_expr, state.value_set);
8484

8585
target.shared_write(
8686
write_guard_expr,

0 commit comments

Comments
 (0)