Skip to content

Properly converts conditions into assertions and assumptions in function contracts #6049

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

Conversation

feliperodri
Copy link
Collaborator

  • Each commit message has a non-empty body, explaining why the change was made.
  • 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).
  • My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@feliperodri feliperodri added bugfix aws Bugs or features of importance to AWS CBMC users Code Contracts Function and loop contracts labels Apr 22, 2021
@feliperodri feliperodri self-assigned this Apr 22, 2021
@@ -104,6 +104,12 @@ class code_contractst
/// \brief Enforce contract of a single function
bool enforce_contract(const std::string &);

/// \brief Create code corresponding to assertion/assumption
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment could be reworded for clarity.

  1. Is it supposed to work only for assertions / assumptions?
  2. It creates goto instructions (not codet), so saying "create code" might be confusing.

Meta comment about the approach: the function seems to be creating a goto_convert and just making a single call to it. Can we make this converter a private member of the code_contractst class instead, and just call the converter.goto_convert directly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I update the comment as suggested, but I don't see how adding converter as a member of this class would be beneficial here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant that converter is being initialized with the same 2 arguments:

goto_convertt converter(symbol_table, log.get_message_handler());

so why not make it a private/protected member, initialize it within code_contractst constructor, and directly call converter.goto_convert in place of convert_to_goto?

But we only call it twice anyway, so not a big deal.

@codecov
Copy link

codecov bot commented Apr 22, 2021

Codecov Report

Merging #6049 (7aefc75) into develop (7663a57) will increase coverage by 0.11%.
The diff coverage is 71.60%.

❗ Current head 7aefc75 differs from pull request most recent head 3363d8c. Consider uploading reports for the commit 3363d8c to get more accurate results
Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #6049      +/-   ##
===========================================
+ Coverage    74.30%   74.42%   +0.11%     
===========================================
  Files         1444     1444              
  Lines       157453   157470      +17     
===========================================
+ Hits        116995   117195     +200     
+ Misses       40458    40275     -183     
Impacted Files Coverage Δ
src/goto-instrument/code_contracts.h 94.11% <ø> (ø)
src/solvers/smt2/smt2_conv.h 100.00% <ø> (ø)
src/ansi-c/c_typecheck_initializer.cpp 64.98% <44.44%> (-9.60%) ⬇️
src/solvers/smt2/smt2_conv.cpp 60.38% <52.94%> (ø)
src/solvers/smt2/smt2_solver.cpp 83.11% <65.51%> (ø)
src/goto-instrument/code_contracts.cpp 84.75% <100.00%> (+0.46%) ⬆️
src/ansi-c/literals/convert_float_literal.cpp 64.28% <0.00%> (-9.53%) ⬇️
src/util/ieee_float.h 75.75% <0.00%> (-6.07%) ⬇️
src/util/bitvector_expr.h 94.73% <0.00%> (-2.88%) ⬇️
... and 22 more

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 8a117bc...3363d8c. Read the comment docs.

@feliperodri feliperodri force-pushed the fix-contracts-asserts-and-assumes branch from d324317 to 7aefc75 Compare April 23, 2021 00:28
@feliperodri feliperodri requested a review from SaswatPadhi April 23, 2021 00:28
@feliperodri
Copy link
Collaborator Author

@SaswatPadhi thank you for the comments, could you take another look?

Copy link
Contributor

@chrisr-diffblue chrisr-diffblue left a comment

Choose a reason for hiding this comment

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

Looks good - and I appreciate the better naming too :-)

Copy link
Contributor

@SaswatPadhi SaswatPadhi left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for the fixes :D

Signed-off-by: Felipe R. Monteiro <felisous@amazon.com>
Signed-off-by: Felipe R. Monteiro <felisous@amazon.com>
New test checks whether CBMC properly verify function contracts
with functions. At this point, we still don't check for purity,
i.e., if functions in contracts are only predicates.

Signed-off-by: Felipe R. Monteiro <felisous@amazon.com>
@feliperodri feliperodri force-pushed the fix-contracts-asserts-and-assumes branch from 7aefc75 to 3363d8c Compare April 23, 2021 15:52
@feliperodri feliperodri merged commit 20408dd into diffblue:develop Apr 23, 2021
@feliperodri feliperodri deleted the fix-contracts-asserts-and-assumes branch April 23, 2021 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws Bugs or features of importance to AWS CBMC users bugfix Code Contracts Function and loop contracts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants