Skip to content

New flag for only processing loop contracts #6184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion regression/contracts/invar_check_break_fail/test.desc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CORE
main.c
--enforce-all-contracts
--apply-loop-contracts
^EXIT=10$
^SIGNAL=0$
^\[main.1\] .* Check loop invariant before entry: SUCCESS$
Expand Down
2 changes: 1 addition & 1 deletion regression/contracts/invar_check_break_pass/test.desc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CORE
main.c
--enforce-all-contracts
--apply-loop-contracts
^EXIT=0$
^SIGNAL=0$
^\[main.1\] .* Check loop invariant before entry: SUCCESS$
Expand Down
2 changes: 1 addition & 1 deletion regression/contracts/invar_check_continue/test.desc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CORE
main.c
--enforce-all-contracts
--apply-loop-contracts
^EXIT=0$
^SIGNAL=0$
^\[main.1\] .* Check loop invariant before entry: SUCCESS$
Expand Down
2 changes: 1 addition & 1 deletion regression/contracts/invar_check_large/test.desc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CORE
main.c
--enforce-all-contracts
--apply-loop-contracts
^EXIT=0$
^SIGNAL=0$
^\[main.1\] .* Check loop invariant before entry: SUCCESS$
Expand Down
2 changes: 1 addition & 1 deletion regression/contracts/invar_check_multiple_loops/test.desc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CORE
main.c
--enforce-all-contracts
--apply-loop-contracts
^EXIT=0$
^SIGNAL=0$
^\[main.1\] .* Check loop invariant before entry: SUCCESS$
Expand Down
2 changes: 1 addition & 1 deletion regression/contracts/invar_check_nested_loops/test.desc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CORE
main.c
--enforce-all-contracts
--apply-loop-contracts
^EXIT=0$
^SIGNAL=0$
^\[main.1\] .* Check loop invariant before entry: SUCCESS$
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CORE
main.c
--enforce-all-contracts --pointer-check
--apply-loop-contracts --pointer-check
^EXIT=0$
^SIGNAL=0$
^\[main.1\] .* Check loop invariant before entry: SUCCESS$
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CORE
main.c
--enforce-all-contracts --pointer-check
--apply-loop-contracts --pointer-check
^EXIT=0$
^SIGNAL=0$
^\[main.1\] .* Check loop invariant before entry: SUCCESS$
Expand Down
2 changes: 1 addition & 1 deletion regression/contracts/invar_check_sufficiency/test.desc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CORE
main.c
--enforce-all-contracts
--apply-loop-contracts
^EXIT=0$
^SIGNAL=0$
^\[main.1\] .* Check loop invariant before entry: SUCCESS$
Expand Down
2 changes: 1 addition & 1 deletion regression/contracts/invar_dynamic_struct_member/test.desc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CORE
main.c
--enforce-all-contracts
--apply-loop-contracts
^EXIT=10$
^SIGNAL=0$
^\[main.1\] .* Check loop invariant before entry: SUCCESS$
Expand Down
2 changes: 1 addition & 1 deletion regression/contracts/invar_havoc_dynamic_array/test.desc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CORE
main.c
--enforce-all-contracts
--apply-loop-contracts
^EXIT=10$
^SIGNAL=0$
^\[main.1\] .* Check loop invariant before entry: SUCCESS$
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CORE
main.c
--enforce-all-contracts
--apply-loop-contracts
^EXIT=10$
^SIGNAL=0$
^\[main.1\] .* Check loop invariant before entry: SUCCESS$
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
KNOWNBUG
main.c
--enforce-all-contracts
--apply-loop-contracts
^EXIT=10$
^SIGNAL=0$
^\[main.1\] .* Check loop invariant before entry: SUCCESS$
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
KNOWNBUG
main.c
--enforce-all-contracts
--apply-loop-contracts
^EXIT=10$
^SIGNAL=0$
^\[main.1\] .* Check loop invariant before entry: SUCCESS$
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
KNOWNBUG
main.c
--enforce-all-contracts
--apply-loop-contracts
^EXIT=10$
^SIGNAL=0$
^\[main.1\] .* Check loop invariant before entry: SUCCESS$
Expand Down
2 changes: 1 addition & 1 deletion regression/contracts/invar_havoc_static_array/test.desc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CORE
main.c
--enforce-all-contracts
--apply-loop-contracts
^EXIT=10$
^SIGNAL=0$
^\[main.1\] .* Check loop invariant before entry: SUCCESS$
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CORE
main.c
--enforce-all-contracts
--apply-loop-contracts
^EXIT=10$
^SIGNAL=0$
^\[main.1\] .* Check loop invariant before entry: SUCCESS$
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CORE
main.c
--enforce-all-contracts
--apply-loop-contracts
^EXIT=10$
^SIGNAL=0$
^\[main.1\] .* Check loop invariant before entry: SUCCESS$
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CORE
main.c
--enforce-all-contracts
--apply-loop-contracts
^EXIT=10$
^SIGNAL=0$
^\[main.1\] .* Check loop invariant before entry: SUCCESS$
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CORE
main.c
--enforce-all-contracts
--apply-loop-contracts
^EXIT=10$
^SIGNAL=0$
^\[main.1\] .* Check loop invariant before entry: SUCCESS$
Expand Down
2 changes: 1 addition & 1 deletion regression/contracts/invar_loop_constant_fail/test.desc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CORE
main.c
--enforce-all-contracts
--apply-loop-contracts
^EXIT=10$
^SIGNAL=0$
^\[main.1\] .* Check loop invariant before entry: SUCCESS$
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CORE
main.c
--enforce-all-contracts
--apply-loop-contracts
^EXIT=0$
^SIGNAL=0$
^\[main.1\] .* Check loop invariant before entry: SUCCESS$
Expand Down
2 changes: 1 addition & 1 deletion regression/contracts/invar_loop_constant_pass/test.desc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CORE
main.c
--enforce-all-contracts
--apply-loop-contracts
^EXIT=0$
^SIGNAL=0$
^\[main.1\] .* Check loop invariant before entry: SUCCESS$
Expand Down
2 changes: 1 addition & 1 deletion regression/contracts/invar_struct_member/test.desc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CORE
main.c
--enforce-all-contracts
--apply-loop-contracts
^EXIT=10$
^SIGNAL=0$
^\[main.1\] .* Check loop invariant before entry: SUCCESS$
Expand Down
2 changes: 1 addition & 1 deletion regression/contracts/invariant_side_effects/test.desc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CORE
main.c
--enforce-all-contracts
--apply-loop-contracts
^EXIT=0$
^SIGNAL=0$
^\[main.1\] .* Check loop invariant before entry: SUCCESS$
Expand Down
2 changes: 1 addition & 1 deletion regression/contracts/quantifiers-loop-01/test.desc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CORE
main.c
--enforce-all-contracts
--apply-loop-contracts
^EXIT=0$
^SIGNAL=0$
^\[main.1\] line .* Check loop invariant before entry: SUCCESS
Expand Down
4 changes: 2 additions & 2 deletions regression/contracts/quantifiers-loop-02/test.desc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CORE
CORE smt-backend
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it work with both back-ends or it was spuriously passing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test works correctly either way, we explicitly provide --z3 in the next line.

I added the tag because on systems that don't have z3 installed and that only run SAT-specific tests, this test should be ignored. Also see #6181.

Currently test tags are not respected within regression/contract. I have reported this already @ #5986 (comment). When that's fixed, this test would be automatically ignored in SAT-only mode.

main.c
--enforce-all-contracts _ --z3
--apply-loop-contracts _ --z3
^EXIT=0$
^SIGNAL=0$
^\[main.\d+\] line .* Check loop invariant before entry: SUCCESS
Expand Down
2 changes: 1 addition & 1 deletion regression/contracts/quantifiers-loop-03/test.desc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CORE
main.c
--enforce-all-contracts
--apply-loop-contracts
^EXIT=0$
^SIGNAL=0$
^\[main.1\] line .* Check loop invariant before entry: SUCCESS
Expand Down
9 changes: 6 additions & 3 deletions src/goto-instrument/code_contracts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,12 @@ bool code_contractst::replace_calls(
return false;
}

void code_contractst::apply_loop_contracts()
{
for(auto &goto_function : goto_functions.function_map)
apply_loop_contract(goto_function.first, goto_function.second);
}

bool code_contractst::replace_calls()
{
std::set<std::string> funs_to_replace;
Expand All @@ -1204,8 +1210,6 @@ bool code_contractst::enforce_contracts()
{
if(has_contract(goto_function.first))
funs_to_enforce.insert(id2string(goto_function.first));
else
apply_loop_contract(goto_function.first, goto_function.second);
}
return enforce_contracts(funs_to_enforce);
}
Expand All @@ -1225,7 +1229,6 @@ bool code_contractst::enforce_contracts(
<< messaget::eom;
continue;
}
apply_loop_contract(goto_function->first, goto_function->second);

if(!has_contract(fun))
{
Expand Down
7 changes: 7 additions & 0 deletions src/goto-instrument/code_contracts.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ class code_contractst
/// \return `true` on failure, `false` otherwise
bool replace_calls();

void apply_loop_contracts();

const symbolt &new_tmp_symbol(
const typet &type,
const source_locationt &source_location,
Expand Down Expand Up @@ -216,6 +218,11 @@ class code_contractst
const irep_idt &mode);
};

#define FLAG_LOOP_CONTRACTS "apply-loop-contracts"
#define HELP_LOOP_CONTRACTS \
" --apply-loop-contracts\n" \
" check and use loop contracts when provided\n"

#define FLAG_REPLACE_CALL "replace-call-with-contract"
#define HELP_REPLACE_CALL \
" --replace-call-with-contract <fun>\n" \
Expand Down
9 changes: 7 additions & 2 deletions src/goto-instrument/goto_instrument_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,8 @@ void goto_instrument_parse_optionst::instrument_goto_program()
}

if(
cmdline.isset(FLAG_REPLACE_CALL) || cmdline.isset(FLAG_REPLACE_ALL_CALLS) ||
cmdline.isset(FLAG_LOOP_CONTRACTS) || cmdline.isset(FLAG_REPLACE_CALL) ||
cmdline.isset(FLAG_REPLACE_ALL_CALLS) ||
cmdline.isset(FLAG_ENFORCE_CONTRACT) ||
cmdline.isset(FLAG_ENFORCE_ALL_CONTRACTS))
{
Expand Down Expand Up @@ -1180,6 +1181,9 @@ void goto_instrument_parse_optionst::instrument_goto_program()
if(cmdline.isset(FLAG_ENFORCE_ALL_CONTRACTS))
if(cont.enforce_contracts())
exit(CPROVER_EXIT_USAGE_ERROR);

if(cmdline.isset(FLAG_LOOP_CONTRACTS))
cont.apply_loop_contracts();
}

if(cmdline.isset("value-set-fi-fp-removal"))
Expand Down Expand Up @@ -1868,7 +1872,8 @@ void goto_instrument_parse_optionst::help()
" --remove-function-body <f> remove the implementation of function <f> (may be repeated)\n"
HELP_REPLACE_CALLS
"\n"
"Function contracts and invariants:\n"
"Code contracts:\n"
HELP_LOOP_CONTRACTS
HELP_REPLACE_CALL
HELP_REPLACE_ALL_CALLS
HELP_ENFORCE_CONTRACT
Expand Down
1 change: 1 addition & 0 deletions src/goto-instrument/goto_instrument_parse_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ Author: Daniel Kroening, [email protected]
"(list-symbols)(list-undefined-functions)" \
"(z3)(add-library)(show-dependence-graph)" \
"(horn)(skip-loops):(model-argc-argv):" \
"(" FLAG_LOOP_CONTRACTS ")" \
"(" FLAG_REPLACE_CALL "):" \
"(" FLAG_REPLACE_ALL_CALLS ")" \
"(" FLAG_ENFORCE_CONTRACT "):" \
Expand Down