Skip to content

Extend and cleanup usability of __CPROVER_{r,w}_ok #4485

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 3 commits into from
Apr 10, 2019

Conversation

tautschnig
Copy link
Collaborator

__CPROVER_r_ok and __CPROVER_w_ok had surprising behaviour that wasn't documented. Make the behaviour less surprising and document it.

  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@danielsn
Copy link
Contributor

danielsn commented Apr 4, 2019

You might want to add a test where "r_ok" should pass, but "w_ok" should fail. Something like

void test() {
  const char* str = "foobar";
  assert(!__CPROVER_w_ok(str, 6));
  assert(__CPROVER_r_ok(str, 6));
}

@tautschnig tautschnig requested a review from kroening as a code owner April 4, 2019 18:53
@tautschnig
Copy link
Collaborator Author

You might want to add a test where "r_ok" should pass, but "w_ok" should fail.

Thank you very much for the suggestion - I have added such a test, but marked it as KNOWNBUG as we do not currently have a way do distinguish lvalues at this point.

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: 7f8f20e).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/107129865
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.

assert(__CPROVER_r_ok(arbitrary_size, n));
assert(__CPROVER_w_ok(arbitrary_size, n));

assert(__CPROVER_r_ok(arbitrary_size, n + 1));
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this succeed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Without --pointer-check any use of __CPROVER_{r,w}_ok is now a no-op (and is now also documented as such), but with --pointer-check this fails as expected (there are two regression tests using the same main.c file included).

Copy link
Member

Choose a reason for hiding this comment

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

Is this what we want? I would find it more intuitive if these were independent.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It does make the implementation a lot easier, and also removes a need for documentation, so that seems much better. The only cost is that we will unconditionally need to run the local alias analysis.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, this will require #4471 to be merged first. And another bug left to be debugged.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, actually there is more to it than just #4471, we also seem to be messing up ID_this elsewhere.

Copy link
Member

Choose a reason for hiding this comment

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

If the cost of the local alias analysis is a concern, there could be a quick scan for the predicate in the function; but so far, that analysis has not been cause for concern.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed, I just need to fix bugs in the C++ and Java front-ends first as the local alias analysis needs to succeed in doing symbol-table lookups...

@tautschnig tautschnig assigned tautschnig and unassigned kroening Apr 5, 2019
@tautschnig tautschnig changed the title Extend and cleanup usability of __CPROVER_{r,w}_ok Extend and cleanup usability of __CPROVER_{r,w}_ok [depends-on: #4471] Apr 8, 2019
@tautschnig tautschnig changed the title Extend and cleanup usability of __CPROVER_{r,w}_ok [depends-on: #4471] Extend and cleanup usability of __CPROVER_{r,w}_ok [depends-on: #4502] Apr 9, 2019
tautschnig added a commit that referenced this pull request Apr 10, 2019
Ensure Java stubbing names parameters [blocks: #4485]
@tautschnig tautschnig changed the title Extend and cleanup usability of __CPROVER_{r,w}_ok [depends-on: #4502] Extend and cleanup usability of __CPROVER_{r,w}_ok Apr 10, 2019
We did not have an explicit test of __CPROVER_{r,w}_ok, only implicit
ones as we use these predicates in our model of the C library. While
preparing a test it became apparent that the predicates are only
evaluated when --pointer-check is set. This caused surprising behaviour
as a negated predicate would result in failing assertions. Instead, make
sure the expression is always evaluated, independent of --pointer-check.
This requires always performing a local alias analysis, even when no
pointer checks are enabled.
@@ -1765,6 +1773,15 @@ void goto_checkt::goto_check(

// the LHS might invalidate any assertion
invalidate(code_assign.lhs());

if(has_subexpr(i.code.op1(), [](const exprt &expr) {
Copy link
Contributor

Choose a reason for hiding this comment

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

i.code.op1 -> code_assign.rhs

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

{
auto rw_ok_cond = rw_ok_check(i.code.op1());
if(rw_ok_cond.has_value())
i.code.op1() = *rw_ok_cond;
Copy link
Contributor

Choose a reason for hiding this comment

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

Hang on, so if any subexpr was an r_ok or w_ok then you overwrite the whole RHS? That seems surprising, what's the rationale for blowing away arbitrary AST nodes here?

Copy link
Collaborator Author

@tautschnig tautschnig Apr 10, 2019

Choose a reason for hiding this comment

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

No, rw_ok_check will take care of only replacing parts of the RHS.

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: 1a8b834).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/107785716
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.

return expr.id() == ID_r_ok || expr.id() == ID_w_ok;
}))
{
auto rw_ok_cond = rw_ok_check(i.code.op0());
Copy link
Contributor

Choose a reason for hiding this comment

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

to_code_return(code).return_value()

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oops, thank you for keeping me from being lazy.

We previously only evaluated __CPROVER_{r,w}_ok in assertions (without
telling anyone that was the case). Instead, evaluate it in all contexts
where it might reasonably appear.
We do not currently have a good way of distinguishing lvalues from
rvalues, and thus actually treat __CPROVER_w_ok and __CPROVER_r_ok the
same. The test shows that this shouldn't always be done.
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: d7dc902).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/107793523
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.

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.

✔️
Passed Diffblue compatibility checks (cbmc commit: 7ecf1f6).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/107802062

@tautschnig tautschnig merged commit ebecdd8 into diffblue:develop Apr 10, 2019
@tautschnig tautschnig deleted the cprover-rw-ok branch April 10, 2019 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants