Skip to content

Commit c500aea

Browse files
author
Daniel Kroening
committed
introduce instructiont::set_condition()
This will eventually allow us to protect the guard data member.
1 parent aac3131 commit c500aea

11 files changed

+49
-12
lines changed

src/analyses/constant_propagator.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -756,11 +756,13 @@ void constant_propagator_ait::replace(
756756
continue;
757757

758758
replace_types_rec(d.values.replace_const, it->code);
759-
replace_types_rec(d.values.replace_const, it->guard);
760759

761760
if(it->is_goto() || it->is_assume() || it->is_assert())
762761
{
763-
constant_propagator_domaint::partial_evaluate(d.values, it->guard, ns);
762+
exprt c = it->get_condition();
763+
replace_types_rec(d.values.replace_const, c);
764+
constant_propagator_domaint::partial_evaluate(d.values, c, ns);
765+
it->set_condition(c);
764766
}
765767
else if(it->is_assign())
766768
{

src/goto-instrument/branch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void branch(
4848
if(i_it->is_goto() && !i_it->get_condition().is_constant())
4949
{
5050
// negate condition
51-
i_it->guard = boolean_negate(i_it->get_condition());
51+
it->set_condition(boolean_negate(i_it->get_condition()));
5252

5353
goto_programt::targett t1=body.insert_after(i_it);
5454
t1->make_function_call(

src/goto-programs/adjust_float_expressions.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,11 @@ void adjust_float_expressions(
202202
adjust_float_expressions(it->code, ns);
203203

204204
if(it->has_condition())
205-
adjust_float_expressions(it->guard, ns);
205+
{
206+
exprt c = it->get_condition();
207+
adjust_float_expressions(c, ns);
208+
it->set_condition(c);
209+
}
206210
}
207211
}
208212

src/goto-programs/goto_convert.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ void goto_convertt::optimize_guarded_gotos(goto_programt &dest)
268268
if(it->get_target()->target_number == it_z->target_number)
269269
{
270270
it->set_target(it_goto_y->get_target());
271-
it->guard = boolean_negate(it->get_condition());
271+
it->set_condition(boolean_negate(it->get_condition()));
272272
it_goto_y->make_skip();
273273
}
274274
}

src/goto-programs/goto_inline_class.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,11 @@ void goto_inlinet::insert_function_body(
318318
replace_location(it->code, target->source_location);
319319

320320
if(it->has_condition())
321-
replace_location(it->guard, target->source_location);
321+
{
322+
exprt c = it->get_condition();
323+
replace_location(c, target->source_location);
324+
it->set_condition(c);
325+
}
322326
}
323327
}
324328

src/goto-programs/goto_program.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ class goto_programt
271271
goto_program_instruction_typet type;
272272

273273
/// Guard for gotos, assume, assert
274-
/// Use get_condition() to read
274+
/// Use get_condition() to read, and set_condition(c) to write.
275275
exprt guard;
276276

277277
/// Does this instruction have a condition?
@@ -287,6 +287,13 @@ class goto_programt
287287
return guard;
288288
}
289289

290+
/// Set the condition of gotos, assume, assert
291+
void set_condition(exprt c)
292+
{
293+
PRECONDITION(has_condition());
294+
guard = std::move(c);
295+
}
296+
290297
// The below will eventually become a single target only.
291298
/// The target for gotos and for start_thread nodes
292299
typedef std::list<instructiont>::iterator targett;

src/goto-programs/link_goto_model.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ static void rename_symbols_in_function(
3535
rename_symbol(iit->code);
3636

3737
if(iit->has_condition())
38-
rename_symbol(iit->guard);
38+
{
39+
exprt c = iit->get_condition();
40+
rename_symbol(c);
41+
iit->set_condition(c);
42+
}
3943
}
4044
}
4145

src/goto-programs/remove_complex.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,11 @@ static void remove_complex(
290290
remove_complex(it->code);
291291

292292
if(it->has_condition())
293-
remove_complex(it->guard);
293+
{
294+
exprt c = it->get_condition();
295+
remove_complex(c);
296+
it->set_condition(c);
297+
}
294298
}
295299
}
296300

src/goto-programs/remove_vector.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,11 @@ void remove_vector(goto_functionst::goto_functiont &goto_function)
223223
remove_vector(it->code);
224224

225225
if(it->has_condition())
226-
remove_vector(it->guard);
226+
{
227+
exprt c = it->get_condition();
228+
remove_vector(c);
229+
it->set_condition(c);
230+
}
227231
}
228232
}
229233

src/goto-programs/rewrite_union.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@ void rewrite_union(goto_functionst::goto_functiont &goto_function)
106106
rewrite_union(it->code);
107107

108108
if(it->has_condition())
109-
rewrite_union(it->guard);
109+
{
110+
exprt c = it->get_condition();
111+
rewrite_union(c);
112+
it->set_condition(c);
113+
}
110114
}
111115
}
112116

src/pointer-analysis/goto_program_dereference.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,11 @@ void goto_program_dereferencet::dereference_instruction(
302302
goto_programt::instructiont &i=*target;
303303

304304
if(i.has_condition())
305-
dereference_expr(i.guard, checks_only, value_set_dereferencet::modet::READ);
305+
{
306+
exprt c = i.get_condition();
307+
dereference_expr(c, checks_only, value_set_dereferencet::modet::READ);
308+
i.set_condition(c);
309+
}
306310

307311
if(i.is_assign())
308312
{

0 commit comments

Comments
 (0)