Skip to content

Commit 3119862

Browse files
committed
Update CLI for applyin loop contracts with dfcc
1 parent 2aec6a9 commit 3119862

File tree

7 files changed

+44
-39
lines changed

7 files changed

+44
-39
lines changed

regression/contracts-dfcc/invar_assigns_opt/test.desc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
CORE
22
main.c
3-
--dfcc main
3+
--dfcc main --apply-loop-contracts
44
^EXIT=0$
55
^SIGNAL=0$
6-
^\[main.\d+\] .* Check loop invariant before entry: SUCCESS$
7-
^\[main.\d+\] .* Check that loop invariant is preserved: SUCCESS$
8-
^\[main.\d+\] .* Check decreases clause on loop iteration: SUCCESS$
9-
^\[main.assertion.\d+\] .* assertion r1 == 0: SUCCESS$
10-
^\[main.\d+\] .* Check loop invariant before entry: SUCCESS$
11-
^\[main.assigns.\d+\] .* Check that s2 is assignable: SUCCESS$
12-
^\[main.assigns.\d+\] .* Check that r2 is assignable: SUCCESS$
13-
^\[main.\d+\] .* Check that loop invariant is preserved: SUCCESS$
14-
^\[main.\d+\] .* Check decreases clause on loop iteration: SUCCESS$
15-
^\[main.assertion.\d+\] .* assertion r2 == 0: SUCCESS$
6+
^\[foo.\d+\] .* Check loop invariant before entry: SUCCESS$
7+
^\[foo.\d+\] .* Check that loop invariant is preserved: SUCCESS$
8+
^\[foo.\d+\] .* Check decreases clause on loop iteration: SUCCESS$
9+
^\[foo.assertion.\d+\] .* assertion r1 == 0: SUCCESS$
10+
^\[foo.\d+\] .* Check loop invariant before entry: SUCCESS$
11+
^\[foo.assigns.\d+\] .* Check that s2 is assignable: SUCCESS$
12+
^\[foo.assigns.\d+\] .* Check that r2 is assignable: SUCCESS$
13+
^\[foo.\d+\] .* Check that loop invariant is preserved: SUCCESS$
14+
^\[foo.\d+\] .* Check decreases clause on loop iteration: SUCCESS$
15+
^\[foo.assertion.\d+\] .* assertion r2 == 0: SUCCESS$
1616
^VERIFICATION SUCCESSFUL$
1717
--
1818
--

regression/contracts-dfcc/loop_assigns-01/test.desc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
CORE
22
main.c
3-
--dfcc main
3+
--dfcc main --apply-loop-contracts
44
^EXIT=10$
55
^SIGNAL=0$
6-
^\[main.\d+\] .* Check loop invariant before entry: SUCCESS$
7-
^\[main.assigns.\d+\] .* Check that i is assignable: SUCCESS$
8-
^\[main.assigns.\d+\] .* Check that b->data\[(.*)i\] is assignable: SUCCESS$
9-
^\[main.\d+\] .* Check that loop invariant is preserved: SUCCESS$
10-
^\[main.assertion.\d+\] .* assertion b->data\[5\] == 0: FAILURE$
6+
^\[foo.\d+\] .* Check loop invariant before entry: SUCCESS$
7+
^\[foo.assigns.\d+\] .* Check that i is assignable: SUCCESS$
8+
^\[foo.assigns.\d+\] .* Check that b->data\[(.*)i\] is assignable: SUCCESS$
9+
^\[foo.\d+\] .* Check that loop invariant is preserved: SUCCESS$
10+
^\[foo.assertion.\d+\] .* assertion b->data\[5\] == 0: FAILURE$
1111
^VERIFICATION FAILED$
1212
--
1313
--
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
CORE
22
main.c
3-
--dfcc main
3+
--dfcc main --apply-loop-contracts
44
^EXIT=0$
55
^SIGNAL=0$
6-
^\[main.\d+\] .* Check loop invariant before entry: SUCCESS$
7-
^\[main.\d+\] .* Check that loop invariant is preserved: SUCCESS$
8-
^\[main.assigns.\d+\] .* Check that i is assignable: SUCCESS$
9-
^\[main.assigns.\d+\] .* Check that b\[(.*)i\] is assignable: SUCCESS$
6+
^\[foo.\d+\] .* Check loop invariant before entry: SUCCESS$
7+
^\[foo.\d+\] .* Check that loop invariant is preserved: SUCCESS$
8+
^\[foo.assigns.\d+\] .* Check that i is assignable: SUCCESS$
9+
^\[foo.assigns.\d+\] .* Check that b\[(.*)i\] is assignable: SUCCESS$
1010
^VERIFICATION SUCCESSFUL$
1111
--
1212
--
13-
This test checks assigns clauses (i, __CPROVER_POINTER_OBJECT(b)) is inferred,
13+
This test checks assigns clauses (i, __CPROVER_object_whole(b)) is inferred,
1414
and widened correctly.

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,13 @@ dfcct::dfcct(
213213
library,
214214
spec_functions,
215215
contract_clauses_codegen),
216-
instrument(goto_model, message_handler, utils, loop_instrument, library),
216+
instrument(
217+
goto_model,
218+
message_handler,
219+
utils,
220+
loop_instrument,
221+
apply_loop_contracts,
222+
library),
217223
max_assigns_clause_size(0)
218224
{
219225
transform_goto_model();

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@ dfcc_instrumentt::dfcc_instrumentt(
4747
message_handlert &message_handler,
4848
dfcc_utilst &utils,
4949
dfcc_loop_instrumentt &loop_instrument,
50+
const bool apply_loop_contracts,
5051
dfcc_libraryt &library)
5152
: goto_model(goto_model),
5253
message_handler(message_handler),
5354
log(message_handler),
5455
utils(utils),
5556
loop_instrument(loop_instrument),
57+
apply_loop_contracts(apply_loop_contracts),
5658
library(library),
5759
ns(goto_model.symbol_table)
5860
{
@@ -475,12 +477,15 @@ void dfcc_instrumentt::instrument_function_body(
475477
auto &body = goto_function.body;
476478

477479
// Instrument all loops in the function.
478-
instrument_loops(
479-
function_id,
480-
goto_function,
481-
write_set,
482-
cfg_info,
483-
function_pointer_contracts);
480+
if(apply_loop_contracts)
481+
{
482+
instrument_loops(
483+
function_id,
484+
goto_function,
485+
write_set,
486+
cfg_info,
487+
function_pointer_contracts);
488+
}
484489

485490
const auto &not_in_loop_filter =
486491
[&](const goto_programt::instructiont::targett &target) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class dfcc_instrumentt
4545
message_handlert &message_handler,
4646
dfcc_utilst &utils,
4747
dfcc_loop_instrumentt &loop_instrument,
48+
const bool apply_loop_contracts,
4849
dfcc_libraryt &library);
4950

5051
/// True if id has `CPROVER_PREFIX` or `__VERIFIER` or `nondet` prefix,
@@ -162,6 +163,7 @@ class dfcc_instrumentt
162163
messaget log;
163164
dfcc_utilst &utils;
164165
dfcc_loop_instrumentt &loop_instrument;
166+
const bool apply_loop_contracts;
165167
dfcc_libraryt &library;
166168
namespacet ns;
167169

src/goto-instrument/goto_instrument_parse_options.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,14 +1169,6 @@ void goto_instrument_parse_optionst::instrument_goto_program()
11691169
"Use a single " FLAG_DFCC " option");
11701170
}
11711171

1172-
if(cmdline.isset(FLAG_LOOP_CONTRACTS))
1173-
{
1174-
throw invalid_command_line_argument_exceptiont(
1175-
"Incompatible options detected",
1176-
"--" FLAG_DFCC " and --" FLAG_LOOP_CONTRACTS,
1177-
"Use either --" FLAG_DFCC " or --" FLAG_LOOP_CONTRACTS);
1178-
}
1179-
11801172
do_indirect_call_and_rtti_removal();
11811173

11821174
const irep_idt harness_id(cmdline.get_value(FLAG_DFCC));
@@ -1215,7 +1207,7 @@ void goto_instrument_parse_optionst::instrument_goto_program()
12151207
: optionalt<irep_idt>{to_enforce.front()},
12161208
allow_recursive_calls,
12171209
to_replace,
1218-
false,
1210+
cmdline.isset(FLAG_LOOP_CONTRACTS),
12191211
to_exclude_from_nondet_static,
12201212
log.get_message_handler());
12211213
}

0 commit comments

Comments
 (0)