Skip to content

Commit e3a9bce

Browse files
committed
Dynamic frames: do not add trivial properties
There is no need to add `ASSERT true` to the collection of properties.
1 parent 0760cd7 commit e3a9bce

File tree

1 file changed

+32
-47
lines changed

1 file changed

+32
-47
lines changed

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

Lines changed: 32 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -693,54 +693,38 @@ void dfcc_instrumentt::instrument_lhs(
693693
check_source_location.set_comment(
694694
"Check that " + from_expr_using_mode(ns, mode, lhs) + " is assignable");
695695

696-
if(cfg_info.must_check_lhs(target))
697-
{
698-
// ```
699-
// IF !write_set GOTO skip_target;
700-
// DECL check_assign: bool;
701-
// CALL check_assign = check_assignment(write_set, &lhs, sizeof(lhs));
702-
// ASSERT(check_assign);
703-
// DEAD check_assign;
704-
// skip_target: SKIP;
705-
// ----
706-
// ASSIGN lhs := rhs;
707-
// ```
696+
// ```
697+
// IF !write_set GOTO skip_target;
698+
// DECL check_assign: bool;
699+
// CALL check_assign = check_assignment(write_set, &lhs, sizeof(lhs));
700+
// ASSERT(check_assign);
701+
// DEAD check_assign;
702+
// skip_target: SKIP;
703+
// ----
704+
// ASSIGN lhs := rhs;
705+
// ```
708706

709-
const auto check_var = dfcc_utilst::create_symbol(
710-
goto_model.symbol_table,
711-
bool_typet(),
712-
function_id,
713-
"__check_lhs_assignment",
714-
lhs_source_location);
707+
const auto check_var = dfcc_utilst::create_symbol(
708+
goto_model.symbol_table,
709+
bool_typet(),
710+
function_id,
711+
"__check_lhs_assignment",
712+
lhs_source_location);
715713

716-
payload.add(goto_programt::make_decl(check_var, lhs_source_location));
714+
payload.add(goto_programt::make_decl(check_var, lhs_source_location));
717715

718-
payload.add(goto_programt::make_function_call(
719-
library.write_set_check_assignment_call(
720-
check_var,
721-
write_set,
722-
typecast_exprt::conditional_cast(
723-
address_of_exprt(lhs), pointer_type(empty_typet{})),
724-
dfcc_utilst::make_sizeof_expr(lhs, ns),
725-
lhs_source_location),
726-
lhs_source_location));
727-
728-
payload.add(
729-
goto_programt::make_assertion(check_var, check_source_location));
730-
payload.add(goto_programt::make_dead(check_var, check_source_location));
731-
}
732-
else
733-
{
734-
// ```
735-
// IF !write_set GOTO skip_target;
736-
// ASSERT(true);
737-
// skip_target: SKIP;
738-
// ----
739-
// ASSIGN lhs := rhs;
740-
// ```
741-
payload.add(
742-
goto_programt::make_assertion(true_exprt(), check_source_location));
743-
}
716+
payload.add(goto_programt::make_function_call(
717+
library.write_set_check_assignment_call(
718+
check_var,
719+
write_set,
720+
typecast_exprt::conditional_cast(
721+
address_of_exprt(lhs), pointer_type(empty_typet{})),
722+
dfcc_utilst::make_sizeof_expr(lhs, ns),
723+
lhs_source_location),
724+
lhs_source_location));
725+
726+
payload.add(goto_programt::make_assertion(check_var, check_source_location));
727+
payload.add(goto_programt::make_dead(check_var, check_source_location));
744728

745729
auto label_instruction =
746730
payload.add(goto_programt::make_skip(lhs_source_location));
@@ -786,7 +770,8 @@ void dfcc_instrumentt::instrument_assign(
786770
auto &write_set = cfg_info.get_write_set(target);
787771

788772
// check the lhs
789-
instrument_lhs(function_id, target, lhs, goto_program, cfg_info);
773+
if(cfg_info.must_check_lhs(target))
774+
instrument_lhs(function_id, target, lhs, goto_program, cfg_info);
790775

791776
// handle dead_object updates (created by __builtin_alloca for instance)
792777
// Remark: we do not really need to track this deallocation since the default
@@ -1018,7 +1003,7 @@ void dfcc_instrumentt::instrument_function_call(
10181003
auto &write_set = cfg_info.get_write_set(target);
10191004

10201005
// Instrument the lhs if any.
1021-
if(target->call_lhs().is_not_nil())
1006+
if(target->call_lhs().is_not_nil() && cfg_info.must_check_lhs(target))
10221007
{
10231008
instrument_lhs(
10241009
function_id, target, target->call_lhs(), goto_program, cfg_info);

0 commit comments

Comments
 (0)