Skip to content

Commit 5002f3b

Browse files
authored
Merge pull request #8449 from tautschnig/use-boolean_negate
Use boolean_negate for immediate simplification
2 parents 2212cd6 + f63dfa9 commit 5002f3b

File tree

6 files changed

+18
-25
lines changed

6 files changed

+18
-25
lines changed

src/goto-instrument/contracts/dynamic-frames/dfcc_contract_clauses_codegen.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ void dfcc_contract_clauses_codegent::encode_assignable_target_group(
110110
new_vars = cleaner.clean(condition, dest, language_mode);
111111

112112
// Jump target if condition is false
113-
auto goto_instruction = dest.add(
114-
goto_programt::make_incomplete_goto(not_exprt{condition}, source_location));
113+
auto goto_instruction = dest.add(goto_programt::make_incomplete_goto(
114+
boolean_negate(condition), source_location));
115115

116116
for(const auto &target : group.targets())
117117
encode_assignable_target(language_mode, target, dest);
@@ -199,8 +199,8 @@ void dfcc_contract_clauses_codegent::encode_freeable_target_group(
199199
new_vars = cleaner.clean(condition, dest, language_mode);
200200

201201
// Jump target if condition is false
202-
auto goto_instruction = dest.add(
203-
goto_programt::make_incomplete_goto(not_exprt{condition}, source_location));
202+
auto goto_instruction = dest.add(goto_programt::make_incomplete_goto(
203+
boolean_negate(condition), source_location));
204204

205205
for(const auto &target : group.targets())
206206
encode_freeable_target(language_mode, target, dest);

src/goto-instrument/contracts/havoc_assigns_clause_targets.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void havoc_assigns_clause_targetst::havoc_if_valid(
6868
skip_program.add(goto_programt::make_skip(source_location_no_checks));
6969

7070
dest.add(goto_programt::make_goto(
71-
skip_target, not_exprt{car.valid_var()}, source_location_no_checks));
71+
skip_target, boolean_negate(car.valid_var()), source_location_no_checks));
7272

7373
if(car.havoc_method == car_havoc_methodt::HAVOC_OBJECT)
7474
{
@@ -142,7 +142,7 @@ void havoc_assigns_clause_targetst::havoc_static_local(
142142
skip_program.add(goto_programt::make_skip(source_location_no_checks));
143143

144144
dest.add(goto_programt::make_goto(
145-
skip_target, not_exprt{car.valid_var()}, source_location_no_checks));
145+
skip_target, boolean_negate(car.valid_var()), source_location_no_checks));
146146

147147
const auto &target_type = car.target().type();
148148
side_effect_expr_nondett nondet(target_type, source_location);

src/goto-instrument/contracts/instrument_spec_assigns.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -656,9 +656,9 @@ exprt instrument_spec_assignst::target_validity_expr(
656656
// (or is NULL if we allow it explicitly).
657657
// This assertion will be falsified whenever `start_address` is invalid or
658658
// not of the right size (or is NULL if we do not allow it explicitly).
659-
auto result =
660-
or_exprt{not_exprt{car.condition()},
661-
w_ok_exprt{car.target_start_address(), car.target_size()}};
659+
auto result = or_exprt{
660+
boolean_negate(car.condition()),
661+
w_ok_exprt{car.target_start_address(), car.target_size()}};
662662

663663
if(allow_null_target)
664664
result.add_to_operands(null_object(car.target_start_address()));

src/goto-instrument/contracts/utils.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ static void append_safe_havoc_code_for_expr(
4141
// skip havocing only if all pointer derefs in the expression are valid
4242
// (to avoid spurious pointer deref errors)
4343
dest.add(goto_programt::make_goto(
44-
skip_target, not_exprt{all_dereferences_are_valid(expr, ns)}, location));
44+
skip_target,
45+
boolean_negate(all_dereferences_are_valid(expr, ns)),
46+
location));
4547

4648
havoc_code_impl();
4749

@@ -433,8 +435,8 @@ static void replace_history_parameter_rec(
433435

434436
// 2.2. Skip storing the history if the expression is invalid
435437
auto goto_instruction = history.add(goto_programt::make_incomplete_goto(
436-
not_exprt{
437-
all_dereferences_are_valid(parameter, namespacet(symbol_table))},
438+
boolean_negate(
439+
all_dereferences_are_valid(parameter, namespacet(symbol_table))),
438440
location));
439441

440442
// 2.3. Add an assignment such that the value pointed to by the new

src/goto-symex/goto_state.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,7 @@ void goto_statet::apply_condition(
145145
if(!is_ssa_expr(lhs) || !goto_symex_can_forward_propagatet(ns)(rhs))
146146
return;
147147

148-
if(rhs.is_true())
149-
apply_condition(equal_exprt{lhs, false_exprt{}}, previous_state, ns);
150-
else if(rhs.is_false())
151-
apply_condition(equal_exprt{lhs, true_exprt{}}, previous_state, ns);
152-
else
153-
UNREACHABLE;
148+
PRECONDITION(rhs.is_constant());
149+
apply_condition(equal_exprt{lhs, boolean_negate(rhs)}, previous_state, ns);
154150
}
155151
}

src/goto-symex/symex_goto.cpp

+2-7
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ void goto_symext::symex_goto(statet &state)
279279
{
280280
// generate assume(false) or a suitable negation if this
281281
// instruction is a conditional goto
282-
exprt negated_guard = not_exprt{new_guard};
282+
exprt negated_guard = boolean_negate(new_guard);
283283
do_simplify(negated_guard);
284284
log.statistics() << "replacing self-loop at "
285285
<< state.source.pc->source_location() << " by assume("
@@ -929,12 +929,7 @@ void goto_symext::loop_bound_exceeded(
929929
{
930930
const std::string loop_number = std::to_string(state.source.pc->loop_number);
931931

932-
exprt negated_cond;
933-
934-
if(guard.is_true())
935-
negated_cond=false_exprt();
936-
else
937-
negated_cond=not_exprt(guard);
932+
exprt negated_cond = boolean_negate(guard);
938933

939934
if(symex_config.unwinding_assertions)
940935
{

0 commit comments

Comments
 (0)