Skip to content

Commit b87d38a

Browse files
authored
Merge pull request #8413 from tautschnig/dfcc-no-unnecessary-check
Dynamic frames: do not add trivial properties
2 parents 0760cd7 + 2214a76 commit b87d38a

File tree

5 files changed

+32
-54
lines changed

5 files changed

+32
-54
lines changed

regression/contracts-dfcc/assigns_enforce_malloc_02/test.desc

-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ CORE dfcc-only
22
main.c
33
--no-malloc-may-fail --dfcc main --enforce-contract f
44
main.c function f
5-
^\[f.assigns.\d+\] line 7 Check that ptr is assignable: SUCCESS$
65
^\[f.assigns.\d+\] line 12 Check that \*ptr is assignable: SUCCESS$
7-
^\[f.assigns.\d+\] line 13 Check that n is assignable: SUCCESS$
86
^EXIT=0$
97
^SIGNAL=0$
108
^VERIFICATION SUCCESSFUL$

regression/contracts-dfcc/assigns_enforce_statics/test.desc

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
CORE dfcc-only
22
main.c
33
--dfcc main --enforce-contract foo _ --pointer-primitive-check
4-
^\[foo.assigns.\d+\] line \d+ Check that y is assignable: SUCCESS$
54
^\[foo.assigns.\d+\] line \d+ Check that foo\$\$1\$\$x is assignable: SUCCESS$
65
^\[foo.assigns.\d+\] line \d+ Check that \*y is assignable: FAILURE$
76
^VERIFICATION FAILED$

regression/contracts-dfcc/loop-freeness-check/test.desc

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
CORE dfcc-only
22
main.c
33
--dfcc main --enforce-contract foo
4-
^\[foo.assigns.\d+\].*Check that i is assignable: SUCCESS$
54
^\[foo.assigns.\d+\].*Check that arr\[(\(.*\))?i\] is assignable: SUCCESS$
65
^VERIFICATION SUCCESSFUL$
76
^EXIT=0$

regression/contracts-dfcc/loop_body_with_hole/test.desc

-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
CORE dfcc-only
22
main.c
33
--dfcc main --apply-loop-contracts
4-
^\[main.assigns.\d+\] line 6 Check that sum_to_k is assignable: SUCCESS$
5-
^\[main.assigns.\d+\] line 7 Check that flag is assignable: SUCCESS$
64
^\[main.assigns.\d+\] line 9 Check that i is assignable: SUCCESS$
75
^\[main.loop_assigns.\d+\] line 9 Check assigns clause inclusion for loop .*: SUCCESS$
86
^\[main.loop_invariant_base.\d+\] line 9 Check invariant before entry for loop .*: SUCCESS$
97
^\[main.loop_invariant_step.\d+\] line 9 Check invariant after step for loop .*: SUCCESS$
108
^\[main.loop_step_unwinding.\d+\] line 9 Check step was unwound for loop .*: SUCCESS$
11-
^\[main.assigns.\d+\] line 17 Check that flag is assignable: SUCCESS$
129
^\[main.assigns.\d+\] line 20 Check that sum_to_k is assignable: SUCCESS$
1310
^VERIFICATION SUCCESSFUL$
1411
^EXIT=0$

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

+32-47
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)