Skip to content

Commit 889225b

Browse files
committed
Do not use value-set supported simplification with multiple threads
Shared pointers may be updated in yet-to-be-executed threads.
1 parent 7cc069d commit 889225b

File tree

10 files changed

+33
-29
lines changed

10 files changed

+33
-29
lines changed
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
KNOWNBUG
1+
CORE
22
main.c
33
-DNO_DEREF
44
^EXIT=0$
55
^SIGNAL=0$
66
^VERIFICATION SUCCESSFUL$
77
--
88
^warning: ignoring
9-
--
10-
Simplification with value sets causes unsound results despite the absence of
11-
dereferencing.

src/goto-symex/goto_symex.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Author: Daniel Kroening, [email protected]
1818
#include <util/mathematical_expr.h>
1919
#include <util/mathematical_types.h>
2020
#include <util/pointer_offset_size.h>
21+
#include <util/simplify_expr.h>
2122
#include <util/simplify_utils.h>
2223
#include <util/std_code.h>
2324
#include <util/string_expr.h>
@@ -29,11 +30,17 @@ Author: Daniel Kroening, [email protected]
2930

3031
#include <climits>
3132

32-
void goto_symext::do_simplify(exprt &expr, const value_sett &value_set)
33+
void goto_symext::do_simplify(exprt &expr, const statet &state)
3334
{
3435
if(symex_config.simplify_opt)
3536
{
36-
simplify_expr_with_value_sett{value_set, language_mode, ns}.simplify(expr);
37+
if(state.threads.size() == 1)
38+
{
39+
simplify_expr_with_value_sett{state.value_set, language_mode, ns}
40+
.simplify(expr);
41+
}
42+
else
43+
simplify(expr, ns);
3744
}
3845
}
3946

@@ -63,7 +70,7 @@ void goto_symext::symex_assign(
6370
// "byte_extract <type> from an_lvalue offset this_rvalue") can affect whether
6471
// we use field-sensitive symbols or not, so L2-rename them up front:
6572
lhs = state.l2_rename_rvalues(lhs, ns);
66-
do_simplify(lhs, state.value_set);
73+
do_simplify(lhs, state);
6774
lhs = state.field_sensitivity.apply(ns, state, std::move(lhs), true);
6875

6976
if(rhs.id() == ID_side_effect)

src/goto-symex/goto_symex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ class goto_symext
526526
/// \param state: Symbolic execution state for current instruction
527527
void symex_catch(statet &state);
528528

529-
virtual void do_simplify(exprt &expr, const value_sett &value_set);
529+
virtual void do_simplify(exprt &expr, const statet &state);
530530

531531
/// Symbolically execute an ASSIGN instruction or simulate such an execution
532532
/// for a synthetic assignment

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, state.value_set);
61+
do_simplify(read_guard_expr, state);
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, state.value_set);
83+
do_simplify(write_guard_expr, state);
8484

8585
target.shared_write(
8686
write_guard_expr,

src/goto-symex/symex_builtin_functions.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ void goto_symext::symex_va_start(
293293

294294
array = clean_expr(std::move(array), state, false);
295295
array = state.rename(std::move(array), ns).get();
296-
do_simplify(array, state.value_set);
296+
do_simplify(array, state);
297297
symex_assign(state, va_array.symbol_expr(), std::move(array));
298298

299299
exprt rhs = address_of_exprt{index_exprt{
@@ -388,7 +388,7 @@ void goto_symext::symex_printf(
388388
exprt tmp_rhs = rhs;
389389
clean_expr(tmp_rhs, state, false);
390390
tmp_rhs = state.rename(std::move(tmp_rhs), ns).get();
391-
do_simplify(tmp_rhs, state.value_set);
391+
do_simplify(tmp_rhs, state);
392392

393393
const exprt::operandst &operands=tmp_rhs.operands();
394394
std::list<exprt> args;
@@ -426,7 +426,7 @@ void goto_symext::symex_printf(
426426
parameter = to_address_of_expr(parameter).object();
427427
clean_expr(parameter, state, false);
428428
parameter = state.rename(std::move(parameter), ns).get();
429-
do_simplify(parameter, state.value_set);
429+
do_simplify(parameter, state);
430430

431431
args.push_back(std::move(parameter));
432432
}
@@ -454,7 +454,7 @@ void goto_symext::symex_input(
454454
for(std::size_t i=1; i<code.operands().size(); i++)
455455
{
456456
exprt l2_arg = state.rename(code.operands()[i], ns).get();
457-
do_simplify(l2_arg, state.value_set);
457+
do_simplify(l2_arg, state);
458458
args.emplace_back(std::move(l2_arg));
459459
}
460460

src/goto-symex/symex_clean_expr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ void goto_symext::process_array_expr(statet &state, exprt &expr)
135135
lift_lets(state, expr);
136136

137137
::process_array_expr(expr, ns);
138-
do_simplify(expr, state.value_set);
138+
do_simplify(expr, state);
139139
}
140140

141141
/// Rewrite index/member expressions in byte_extract to offset
@@ -178,7 +178,7 @@ void goto_symext::lift_let(statet &state, const let_exprt &let_expr)
178178
{
179179
exprt let_value = clean_expr(let_expr.value(), state, false);
180180
let_value = state.rename(std::move(let_value), ns).get();
181-
do_simplify(let_value, state.value_set);
181+
do_simplify(let_value, state);
182182

183183
exprt::operandst value_assignment_guard;
184184
symex_assignt{

src/goto-symex/symex_dereference.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ exprt goto_symext::address_arithmetic(
101101
// recursive call
102102
result = address_arithmetic(be, state, keep_array);
103103

104-
do_simplify(result, state.value_set);
104+
do_simplify(result, state);
105105
}
106106
else if(expr.id()==ID_dereference)
107107
{
@@ -158,7 +158,7 @@ exprt goto_symext::address_arithmetic(
158158

159159
result = address_arithmetic(be, state, keep_array);
160160

161-
do_simplify(result, state.value_set);
161+
do_simplify(result, state);
162162
}
163163
else
164164
result=address_of_exprt(result);
@@ -330,7 +330,7 @@ void goto_symext::dereference_rec(
330330
}
331331
}
332332

333-
do_simplify(tmp1, state.value_set);
333+
do_simplify(tmp1, state);
334334

335335
if(symex_config.run_validation_checks)
336336
{
@@ -537,7 +537,7 @@ void goto_symext::dereference(exprt &expr, statet &state, bool write)
537537
// when all we need is
538538
// s1 := s1 with (member := X) [and guard b]
539539
// s2 := s2 with (member := X) [and guard !b]
540-
do_simplify(expr, state.value_set);
540+
do_simplify(expr, state);
541541

542542
if(symex_config.run_validation_checks)
543543
{

src/goto-symex/symex_goto.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ void goto_symext::symex_goto(statet &state)
118118
// generate assume(false) or a suitable negation if this
119119
// instruction is a conditional goto
120120
exprt negated_guard = boolean_negate(new_guard);
121-
do_simplify(negated_guard, state.value_set);
121+
do_simplify(negated_guard, state);
122122
log.statistics() << "replacing self-loop at "
123123
<< state.source.pc->source_location() << " by assume("
124124
<< from_expr(ns, state.source.function_id, negated_guard)

src/goto-symex/symex_main.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ void goto_symext::symex_assert(
157157
// First, push negations in and perhaps convert existential quantifiers into
158158
// universals:
159159
if(has_subexpr(condition, ID_exists) || has_subexpr(condition, ID_forall))
160-
do_simplify(condition, state.value_set);
160+
do_simplify(condition, state);
161161

162162
// Second, L2-rename universal quantifiers:
163163
if(has_subexpr(condition, ID_forall))
@@ -167,7 +167,7 @@ void goto_symext::symex_assert(
167167
exprt l2_condition = state.rename(std::move(condition), ns).get();
168168

169169
// now try simplifier on it
170-
do_simplify(l2_condition, state.value_set);
170+
do_simplify(l2_condition, state);
171171

172172
std::string msg = id2string(instruction.source_location().get_comment());
173173
if(msg.empty())
@@ -200,7 +200,7 @@ void goto_symext::symex_assume(statet &state, const exprt &cond)
200200
{
201201
exprt simplified_cond = clean_expr(cond, state, false);
202202
simplified_cond = state.rename(std::move(simplified_cond), ns).get();
203-
do_simplify(simplified_cond, state.value_set);
203+
do_simplify(simplified_cond, state);
204204

205205
// It would be better to call try_filter_value_sets after apply_condition,
206206
// but it is not currently possible. See the comment at the beginning of
@@ -848,13 +848,13 @@ void goto_symext::try_filter_value_sets(
848848
// without another round of constant propagation.
849849
// It would be sufficient to replace this call to do_simplify() with
850850
// something that just replaces `*&x` with `x` whenever it finds it.
851-
do_simplify(modified_condition, state.value_set);
851+
do_simplify(modified_condition, state);
852852

853853
state.record_events.push(false);
854854
modified_condition = state.rename(std::move(modified_condition), ns).get();
855855
state.record_events.pop();
856856

857-
do_simplify(modified_condition, state.value_set);
857+
do_simplify(modified_condition, state);
858858

859859
if(jump_taken_value_set && modified_condition == false)
860860
{

src/goto-symex/symex_other.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,14 @@ void goto_symext::symex_other(
151151
{
152152
src_array = make_byte_extract(
153153
src_array, from_integer(0, c_index_type()), dest_array.type());
154-
do_simplify(src_array, state.value_set);
154+
do_simplify(src_array, state);
155155
}
156156
else
157157
{
158158
// ID_array_replace
159159
dest_array = make_byte_extract(
160160
dest_array, from_integer(0, c_index_type()), src_array.type());
161-
do_simplify(dest_array, state.value_set);
161+
do_simplify(dest_array, state);
162162
}
163163
}
164164

@@ -197,7 +197,7 @@ void goto_symext::symex_other(
197197
{
198198
auto array_size = size_of_expr(array_expr.type(), ns);
199199
CHECK_RETURN(array_size.has_value());
200-
do_simplify(array_size.value(), state.value_set);
200+
do_simplify(array_size.value(), state);
201201
array_expr = make_byte_extract(
202202
array_expr,
203203
from_integer(0, c_index_type()),

0 commit comments

Comments
 (0)