-
Notifications
You must be signed in to change notification settings - Fork 274
Enforce purity on missing assigns clause #6074
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
Conversation
49f605d
to
5f37ed6
Compare
I just realized that the PR doesn't actually add support for |
Codecov Report
@@ Coverage Diff @@
## develop #6074 +/- ##
===========================================
+ Coverage 74.17% 74.44% +0.26%
===========================================
Files 1446 1446
Lines 157784 157778 -6
===========================================
+ Hits 117036 117456 +420
+ Misses 40748 40322 -426
Continue to review full report at Codecov.
|
Yes, renaming the PR would help! |
5f37ed6
to
a688e79
Compare
I think this looks ok. There are some small tidying bits I noted, and I think it will fail regression tests (but this should just be fixing the test regexs). The only bit that is unclear to me is whether removing the old code that used to enforce failure is safe and won't break expected functionality. (Why was it written if this is fairly clearly failing when there is no assignment if this should instead be pure and not evaluated as a failure?) |
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.
Approving since I don't have any additional comments, but let's fix all of the comments from @TGWDB.
CBMC currently doesn't enforce assigns clauses if there isn't one. However, whenever enforcing a function contract, the absence of an assigns clause should be interpreted as an empty write set (i.e., no inputs will be modified by this function). CBMC now properly checks for empty assigns clause behavior. Signed-off-by: Felipe R. Monteiro <[email protected]>
a688e79
to
c29b69a
Compare
@TGWDB Before, when enforcing a contract for function foo, CBMC would fail if any of its inner functions don't have an assigns clause, even if the inner function preserve all inputs. This behavior is too restrict. If a function doesn't change any of the inputs, its assigns clause should be empty. On this PR, we do one step further and instead of adding a false assertion for functions without assigns clause, we check for purity of the inner functions (i.e., they don't change any of the inputs). |
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.
Looks good to me, thanks - with just one small sanity check on my part :-)
@@ -634,9 +622,6 @@ bool code_contractst::add_pointer_checks(const std::string &function_name) | |||
const auto &type = to_code_with_contract_type(function_symbol.type); | |||
|
|||
exprt assigns_expr = type.assigns(); | |||
// Return if there are no reference checks to perform. | |||
if(assigns_expr.is_nil()) | |||
return false; |
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.
Just a check - is there a test case that will fail if this code ever gets inserted again? :-) It superficially looks like an "obvious" optimisation, so I can imaging someone in the future re-adding it with good intent.
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.
If somebody add this back, assigns_enforce_15
will fail. For this case, we have assignments, but because there is no assigns clause, we wouldn't even complain about them. we should report an error in this case, because we want to enforce contracts across all functions using --enforce-all-contracts
flag.
CBMC currently doesn't enforce assigns clauses if there isn't one.
However, whenever enforcing a function contract, the absence of an
assigns clause should be interpreted as an empty write set
(i.e., no inputs will be modified by this function).
CBMC now properly checks for empty assigns clause behavior.
Signed-off-by: Felipe R. Monteiro [email protected]