Skip to content

Add a __CPROVER_postcondition builtin #4921

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 4 commits into from
Aug 11, 2019

Conversation

angelhof
Copy link
Contributor

@angelhof angelhof commented Jul 17, 2019

Add a builtin __CPROVER_postcondition builtin function that internally becomes an assert (like __CPROVER_precondition).

This will be used (by a later PR) to turn function preconditions, and postconditions to code contracts.

@smowton
Copy link
Contributor

smowton commented Jul 17, 2019

Please add a regression test exercising the new code. There actually don't appear to be any exercising __CPROVER_precondition either, so if you're feeling generous add that too!

@angelhof
Copy link
Contributor Author

Please add a regression test exercising the new code. There actually don't appear to be any exercising __CPROVER_precondition either, so if you're feeling generous add that too!

@smowton Thanks, I will add a regression test for both. On a different note, why is CPP-LINT in travis complaining only for the newly added line and not for the ones above that use __CPROVER_?

@owen-mc-diffblue
Copy link
Contributor

I think CPP-LINT in travis only checks newly added lines. This is so that things can be slowly fixed as we go, rather than having to fix them all at once so that we can see if we add any new ones.

@angelhof
Copy link
Contributor Author

I think CPP-LINT in travis only checks newly added lines. This is so that things can be slowly fixed as we go, rather than having to fix them all at once so that we can see if we add any new ones.

Thanks. Shouldn't this check in cpplint.py only check for uses of __CPROVER_ in strings? I am not aware of any way to define a function using a string literal (CPROVER_PREFIX).

@owen-mc-diffblue
Copy link
Contributor

@tautschnig, you wrote that check in cpplint.py (last October), can you help @angelhof?

@smowton
Copy link
Contributor

smowton commented Jul 22, 2019

Here's the check: https://github.com/diffblue/cbmc/blob/develop/scripts/cpplint.py#L4607

I would suggest simply whitelisting paths beginning with regession/ or src/ansi-c/library/` for that particular check. Hard-coding that should be fine given the check itself is our own custom invention.

@angelhof
Copy link
Contributor Author

Here's the check: https://github.com/diffblue/cbmc/blob/develop/scripts/cpplint.py#L4607

I would suggest simply whitelisting paths beginning with regession/ or src/ansi-c/library/` for that particular check. Hard-coding that should be fine given the check itself is our own custom invention.

Wouldn't something like r'\".*__CPROVER_.*\"' make more sense? Since (from what I understand) this check suggests using CPROVER_PREFIX in string literals and not in general (e.g. function names).

@smowton
Copy link
Contributor

smowton commented Jul 23, 2019

That precise regex would misfire for f("Hello", __CPROVER_blah(y, z), "world"), but looking for precisely "__CPROVER_ would probably do the trick 90% of the time. I'd be happy with either solution.

@angelhof
Copy link
Contributor Author

@smowton I don't have any preference between the two. I could implement any of them in a separate PR. Is this PR blocked until the lint check succeeds?

@smowton
Copy link
Contributor

smowton commented Jul 23, 2019

Yes without administrative intervention. I'd recommend making the change as a second commit in this PR.

@angelhof angelhof force-pushed the cprover-postcondition branch from 6ad9a09 to 44197bb Compare July 26, 2019 11:38
@angelhof angelhof requested a review from thk123 as a code owner July 26, 2019 11:38
@codecov-io
Copy link

Codecov Report

Merging #4921 into develop will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #4921      +/-   ##
===========================================
+ Coverage    69.27%   69.28%   +<.01%     
===========================================
  Files         1307     1307              
  Lines       108145   108148       +3     
===========================================
+ Hits         74918    74926       +8     
+ Misses       33227    33222       -5
Impacted Files Coverage Δ
src/goto-programs/builtin_functions.cpp 45.76% <100%> (+0.31%) ⬆️
src/solvers/flattening/boolbv_get.cpp 78.66% <0%> (+3.33%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 103b2dc...44197bb. Read the comment docs.

@angelhof
Copy link
Contributor Author

Could someone review this?

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

⚠️
This PR failed Diffblue compatibility checks (cbmc commit: 44197bb).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/120852254
Status will be re-evaluated on next push.
Common spurious failures include: the cbmc commit has disappeared in the mean time (e.g. in a force-push); the author is not in the list of contributors (e.g. first-time contributors); compatibility was already broken by an earlier merge.

@angelhof
Copy link
Contributor Author

@peterschrammel could you review this?

@angelhof
Copy link
Contributor Author

angelhof commented Aug 1, 2019

@peterschrammel @thk123 could you review this PR?

Copy link
Contributor

@thk123 thk123 left a comment

Choose a reason for hiding this comment

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

Approving the changes to cpplint only - seems like there has been more than enough eyes on the rest!

Copy link
Collaborator

@tautschnig tautschnig left a comment

Choose a reason for hiding this comment

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

The empty commit bodies plus the absence of other documentation make this hard for anyone to use effectively. Otherwise looks good to me.

@@ -2,6 +2,7 @@ void __CPROVER_assume(__CPROVER_bool assumption);
void __VERIFIER_assume(__CPROVER_bool assumption);
void __CPROVER_assert(__CPROVER_bool assertion, const char *description);
void __CPROVER_precondition(__CPROVER_bool precondition, const char *description);
void __CPROVER_postcondition(__CPROVER_bool assertion, const char *description);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Random place for a comment: I think this strictly requires documentation. When should users make use of this? I note that the commit message doesn't have a body either, so it's really hard to see when that should be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Where is a good place to add documentation for this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

As discussed elsewhere: doc/cprover-manual/cbmc-assertions.md is likely the best place for this. @kroening Would you be able to contribute some documentation of __CPROVER_precondition, which AFAIK never got documented?

Copy link
Member

Choose a reason for hiding this comment

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

I would structure this differently.
__CPROVER_precondition was introduced as a means to add preconditions to library functions, i.e., it was never meant to be used by anyone but CBMC developers.

The new feature, which is contract checking, is a different use-case, and externalises this to users of CBMC. My experience is that users like manuals that are structured by use-case. Thus, I would suggest to add a new chapter, say titled "Modular Verification using Code Contracts", or the like, to discuss this use-case separately.

Copy link
Collaborator

Choose a reason for hiding this comment

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

[...] never meant to be used by anyone but CBMC developers.

While this is a good intention, I don't think it will remain as constrained if people find it useful in other places as well. Anything that can be used will be used at some point...

The added builtin function, is transformed into an assert (like __CPROVER_precondition)
by the goto-cc pass. The reason why it was added, is to allow an analysis on the AST
to extract the postconditions from function bodies, to extend their function contracts.
@angelhof angelhof force-pushed the cprover-postcondition branch from 44197bb to 59ab9e9 Compare August 7, 2019 22:16
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

⚠️
This PR failed Diffblue compatibility checks (cbmc commit: 59ab9e9).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/122362598
Status will be re-evaluated on next push.
Common spurious failures include: the cbmc commit has disappeared in the mean time (e.g. in a force-push); the author is not in the list of contributors (e.g. first-time contributors); compatibility was already broken by an earlier merge.

@angelhof angelhof force-pushed the cprover-postcondition branch from 59ab9e9 to f4a6f43 Compare August 8, 2019 21:07
@angelhof
Copy link
Contributor Author

angelhof commented Aug 8, 2019

The lint error is fixed in #5000.

@angelhof angelhof force-pushed the cprover-postcondition branch from 8746b52 to 3811798 Compare August 8, 2019 22:01
@angelhof angelhof force-pushed the cprover-postcondition branch from 3811798 to 119ce60 Compare August 9, 2019 17:58
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

⚠️
This PR failed Diffblue compatibility checks (cbmc commit: 119ce60).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/122640419
Status will be re-evaluated on next push.
Common spurious failures include: the cbmc commit has disappeared in the mean time (e.g. in a force-push); the author is not in the list of contributors (e.g. first-time contributors); compatibility was already broken by an earlier merge.

@karkhaz karkhaz merged commit d263955 into diffblue:develop Aug 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants