-
Notifications
You must be signed in to change notification settings - Fork 277
Enforce __CPROVER_loop_invariant contracts in goto-instrument #5884
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
Enforce __CPROVER_loop_invariant contracts in goto-instrument #5884
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #5884 +/- ##
===========================================
+ Coverage 72.90% 72.95% +0.04%
===========================================
Files 1425 1425
Lines 154282 154281 -1
===========================================
+ Hits 112485 112561 +76
+ Misses 41797 41720 -77
Continue to review full report at Codecov.
|
[...]
@SaswatPadhi Please make sure you sync with @feliperodri on this to avoid duplicate work. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd aslo recommend you to break down the PR into at least two commits: one for the changes in code_contracts.*
files and another for the updates in the regression tests.
a0a7304
to
eae9473
Compare
4c4c2cd
to
5564547
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems good. Comments are only minor improvements. Thanks for the contribution.
// look at all function calls | ||
Forall_goto_program_instructions(ins, goto_function.body) | ||
if(ins->is_function_call()) | ||
apply_contract(goto_function.body, ins); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still d20bbe1
Case in point: In this case it's a bit hard for me to see why this loop was removed. It's combined with a fairly straightforward refactoring of the preceding loop so it's difficult for me see if this was an intentional change or a mistake that snuck in during refactoring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This particular function was perhaps the old entry point for the old contracts flag. It was used to replace loops with invariant contracts and function calls with function contracts. I removed this loop intentionally because the replacement of calls with contracts now happens in replace_calls
. You can see a very similar loop in replace_calls
:
cbmc/src/goto-instrument/code_contracts.cpp
Lines 894 to 916 in 947fb8f
for(auto &goto_function : goto_functions.function_map) | |
{ | |
Forall_goto_program_instructions(ins, goto_function.second.body) | |
{ | |
if(ins->is_function_call()) | |
{ | |
const code_function_callt &call = ins->get_function_call(); | |
// TODO we don't handle function pointers | |
if(call.function().id() != ID_symbol) | |
continue; | |
const irep_idt &fun_name = | |
to_symbol_expr(call.function()).get_identifier(); | |
auto found = std::find( | |
funs_to_replace.begin(), funs_to_replace.end(), id2string(fun_name)); | |
if(found == funs_to_replace.end()) | |
continue; | |
fail |= apply_contract(goto_function.second.body, ins); | |
} | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with the actual changes, clang-format weirdness can be resolved (see my reply to your slack message), would prefer if the first commit was split up further before merging but not a blocker.
The `code_contracts` function was unused and the function contract application part of it was improved in `replace_calls`. This commit: - removes this old unused functionality, - renames `code_contracts` to `apply_loop_contract`, and - renames `apply_contract` to `apply_function_contract`.
Loop invariant annotations were being silently ignored when goto-instrument was invoked with `--enforce-contracts` or `--enforce-contract`. These flags now enforce both function and loop invariant contracts.
5564547
to
142ff6a
Compare
- Moved comments from .c files to descriptions in .desc files - Added new tests to check multiple loops, nested loops, loop-local variables - Enabled and clarified a regression test that was flagged as a buggy one
142ff6a
to
45b6d72
Compare
Thanks for the review, @martin-cs and @hannes-steffenhagen-diffblue. I think I have addressed all your comments now. Please take another look and let me know if I should make any more changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep; looks good.
I realise this isn't really the right place to ask this but... if you are considering a reworking / rewrite of the code contracts stuff:
|
Hi @martin-cs,
|
|
This PR resolves #5882.
It enforces
__CPROVER_loop_invariant
contract (in addition to function contracts) when--enforce-all-contracts
or--enforce-contract <fun>
flag is used withgoto-instrument
.NOTE: The
code_contracts.h
andcode_contracts.cpp
files need a thorough clean up -- the return types seem inconsistent (void
vsbool
) for many functions that have similar behavior, and several functions don't use the C++11 range-based for loops etc. I would make a separate PR later for refactoring and cleanup. This PR only adds the invariant checking back into the contracts flags and enables related regression tests.