Skip to content

Commit 3fb0408

Browse files
smowtontautschnig
authored andcommitted
Reinstate symex-deref's write parameter
field_sensitivity::apply needs to avoid expanding struct-typed symbols into fields when they're being used as lvalues.
1 parent 6724b09 commit 3fb0408

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

src/goto-symex/goto_symex.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,9 @@ class goto_symext
279279
void initialize_auto_object(const exprt &, statet &);
280280
void process_array_expr(statet &, exprt &);
281281
exprt make_auto_object(const typet &, statet &);
282-
virtual void dereference(exprt &, statet &);
282+
virtual void dereference(exprt &, statet &, bool write);
283283

284-
void dereference_rec(exprt &, statet &);
284+
void dereference_rec(exprt &, statet &, bool write);
285285
exprt address_arithmetic(
286286
const exprt &,
287287
statet &,

src/goto-symex/symex_clean_expr.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ void goto_symext::clean_expr(
175175
const bool write)
176176
{
177177
replace_nondet(expr, path_storage.build_symex_nondet);
178-
dereference(expr, state);
178+
dereference(expr, state, write);
179179

180180
// make sure all remaining byte extract operations use the root
181181
// object to avoid nesting of with/update and byte_update when on

src/goto-symex/symex_dereference.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ exprt goto_symext::address_arithmetic(
7070

7171
// there could be further dereferencing in the offset
7272
exprt offset=be.offset();
73-
dereference_rec(offset, state);
73+
dereference_rec(offset, state, false);
7474

7575
result=plus_exprt(result, offset);
7676

@@ -106,14 +106,14 @@ exprt goto_symext::address_arithmetic(
106106
// just grab the pointer, but be wary of further dereferencing
107107
// in the pointer itself
108108
result=to_dereference_expr(expr).pointer();
109-
dereference_rec(result, state);
109+
dereference_rec(result, state, false);
110110
}
111111
else if(expr.id()==ID_if)
112112
{
113113
if_exprt if_expr=to_if_expr(expr);
114114

115115
// the condition is not an address
116-
dereference_rec(if_expr.cond(), state);
116+
dereference_rec(if_expr.cond(), state, false);
117117

118118
// recursive call
119119
if_expr.true_case() =
@@ -130,7 +130,7 @@ exprt goto_symext::address_arithmetic(
130130
{
131131
// give up, just dereference
132132
result=expr;
133-
dereference_rec(result, state);
133+
dereference_rec(result, state, false);
134134

135135
// turn &array into &array[0]
136136
if(result.type().id() == ID_array && !keep_array)
@@ -198,7 +198,7 @@ exprt goto_symext::address_arithmetic(
198198
/// such as `&struct.flexible_array[0]` (see inline comments in code).
199199
/// For full details of this method's pointer replacement and potential side-
200200
/// effects see \ref goto_symext::dereference
201-
void goto_symext::dereference_rec(exprt &expr, statet &state)
201+
void goto_symext::dereference_rec(exprt &expr, statet &state, bool write)
202202
{
203203
if(expr.id()==ID_dereference)
204204
{
@@ -221,7 +221,7 @@ void goto_symext::dereference_rec(exprt &expr, statet &state)
221221
tmp1.swap(to_dereference_expr(expr).pointer());
222222

223223
// first make sure there are no dereferences in there
224-
dereference_rec(tmp1, state);
224+
dereference_rec(tmp1, state, false);
225225

226226
// we need to set up some elaborate call-backs
227227
symex_dereference_statet symex_dereference_state(state, ns);
@@ -259,7 +259,7 @@ void goto_symext::dereference_rec(exprt &expr, statet &state)
259259
tmp.add_source_location()=expr.source_location();
260260

261261
// recursive call
262-
dereference_rec(tmp, state);
262+
dereference_rec(tmp, state, write);
263263

264264
expr.swap(tmp);
265265
}
@@ -297,17 +297,17 @@ void goto_symext::dereference_rec(exprt &expr, statet &state)
297297
to_address_of_expr(tc_op).object(),
298298
from_integer(0, index_type())));
299299

300-
dereference_rec(expr, state);
300+
dereference_rec(expr, state, write);
301301
}
302302
else
303303
{
304-
dereference_rec(tc_op, state);
304+
dereference_rec(tc_op, state, write);
305305
}
306306
}
307307
else
308308
{
309309
Forall_operands(it, expr)
310-
dereference_rec(*it, state);
310+
dereference_rec(*it, state, write);
311311
}
312312
}
313313

@@ -348,7 +348,7 @@ void goto_symext::dereference_rec(exprt &expr, statet &state)
348348
/// dereferenced. If new objects are created by this mechanism then
349349
/// state will be altered (by `symex_assign`) to initialise them.
350350
/// See \ref auto_objects.cpp for details.
351-
void goto_symext::dereference(exprt &expr, statet &state)
351+
void goto_symext::dereference(exprt &expr, statet &state, bool write)
352352
{
353353
// The expression needs to be renamed to level 1
354354
// in order to distinguish addresses of local variables
@@ -358,7 +358,7 @@ void goto_symext::dereference(exprt &expr, statet &state)
358358
exprt l1_expr = state.rename<L1>(expr, ns).get();
359359

360360
// start the recursion!
361-
dereference_rec(l1_expr, state);
361+
dereference_rec(l1_expr, state, write);
362362
// dereferencing may introduce new symbol_exprt
363363
// (like __CPROVER_memory)
364364
expr = state.rename<L1>(std::move(l1_expr), ns).get();

0 commit comments

Comments
 (0)