Skip to content

Commit 3ba0bc1

Browse files
committed
Field sensitivity: using apply is now always safe
With the changes from 6193534 it is safe to call `apply` even when doing field assignments: the right-hand side will not be a divisible compound (which we previously sought to protect from field expansion). This makes field sensitivity stateless, and all methods are `const`. They are not static, however, as the constructor initialises configuration options (which would otherwise need to be passed to each call). We can then also avoid a level of indirection through `apply` and call `get_fields` directly in two cases.
1 parent 7aaff0d commit 3ba0bc1

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

src/goto-symex/field_sensitivity.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ exprt field_sensitivityt::apply(
2323
ssa_exprt ssa_expr,
2424
bool write) const
2525
{
26-
if(!run_apply || write)
26+
if(write)
2727
return std::move(ssa_expr);
2828
else
2929
return get_fields(ns, state, ssa_expr);
@@ -35,9 +35,6 @@ exprt field_sensitivityt::apply(
3535
exprt expr,
3636
bool write) const
3737
{
38-
if(!run_apply)
39-
return expr;
40-
4138
if(expr.id() != ID_address_of)
4239
{
4340
Forall_operands(it, expr)
@@ -46,7 +43,7 @@ exprt field_sensitivityt::apply(
4643

4744
if(!write && is_ssa_expr(expr))
4845
{
49-
return apply(ns, state, to_ssa_expr(expr), write);
46+
return get_fields(ns, state, to_ssa_expr(expr));
5047
}
5148
else if(
5249
!write && expr.id() == ID_member &&
@@ -231,17 +228,14 @@ void field_sensitivityt::field_assignments(
231228
const ssa_exprt &lhs,
232229
const exprt &rhs,
233230
symex_targett &target,
234-
bool allow_pointer_unsoundness)
231+
bool allow_pointer_unsoundness) const
235232
{
236-
const exprt lhs_fs = apply(ns, state, lhs, false);
233+
const exprt lhs_fs = get_fields(ns, state, lhs);
237234

238235
if(lhs != lhs_fs)
239236
{
240-
bool run_apply_bak = run_apply;
241-
run_apply = false;
242237
field_assignments_rec(
243238
ns, state, lhs_fs, rhs, target, allow_pointer_unsoundness);
244-
run_apply = run_apply_bak;
245239
}
246240
}
247241

@@ -261,7 +255,7 @@ void field_sensitivityt::field_assignments_rec(
261255
const exprt &lhs_fs,
262256
const exprt &ssa_rhs,
263257
symex_targett &target,
264-
bool allow_pointer_unsoundness)
258+
bool allow_pointer_unsoundness) const
265259
{
266260
if(is_ssa_expr(lhs_fs))
267261
{

src/goto-symex/field_sensitivity.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class field_sensitivityt
108108
const ssa_exprt &lhs,
109109
const exprt &rhs,
110110
symex_targett &target,
111-
bool allow_pointer_unsoundness);
111+
bool allow_pointer_unsoundness) const;
112112

113113
/// Turn an expression \p expr into a field-sensitive SSA expression.
114114
/// Field-sensitive SSA expressions have individual symbols for each
@@ -154,12 +154,10 @@ class field_sensitivityt
154154
/// \param expr: the expression to evaluate
155155
/// \return False, if and only if, \p expr would be a single field-sensitive
156156
/// SSA expression.
157+
NODISCARD
157158
bool is_divisible(const ssa_exprt &expr) const;
158159

159160
private:
160-
/// whether or not to invoke \ref field_sensitivityt::apply
161-
bool run_apply = true;
162-
163161
const std::size_t max_field_sensitivity_array_size;
164162

165163
const bool should_simplify;
@@ -170,7 +168,7 @@ class field_sensitivityt
170168
const exprt &lhs_fs,
171169
const exprt &ssa_rhs,
172170
symex_targett &target,
173-
bool allow_pointer_unsoundness);
171+
bool allow_pointer_unsoundness) const;
174172

175173
exprt simplify_opt(exprt e, const namespacet &ns) const;
176174
};

0 commit comments

Comments
 (0)