Skip to content
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

Use goto-analyzer to add assumptions, assertions and code contracts #7964

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

martin-cs
Copy link
Collaborator

This is a work-in-progress PR posted for general feedback and early opinions. It adds a new 'task' to goto-analyzer which runs the abstract interpreter, converts the domains to predicates and then adds them into the goto program as assumptions, assertions or as contracts. Assumptions are intended to aid other analysis tools which can use (but not necessarily create) inductive invariants. Assertions are intended to give a way to cross-test the abstract interpreter using CBMC. Contracts are intended to give better default contracts for code that does not have them and to help users in writing the obvious but tedious parts.

Things that still need some work:

  • the global variables generated by return removal can be included in expressions. These need to be omitted from assume and assert and converted to __CPROVER_return in the contracts.
  • the generated expressions are reduced to only include things accessible in the current scope (globals, locals and arguments). This creates a problem with pointers that point to things outside of the current scope (i.e. pass by reference). In this case the expression for the pointer will simply be true which is correct and over-approximate but not very helpful. It is not immediately clear what the "right" approach is.
  • back-edges can be annotated but this is not the same as the notion of loop that the contracts use. I'm going to use the contracts loop analysis code to give compatible annotations.
  • assigns contracts are not generated yet as they need additional support for domain difference.
  • at the moment all relevant (non-trivial) information is given, with domain difference it should be possible to give just the things that have changed since the last added assumption or assertion.

@martin-cs martin-cs marked this pull request as draft October 17, 2023 07:51
@martin-cs martin-cs force-pushed the feature/goto-analyzer-instrument-task branch from 6e78afd to 1d4a86e Compare October 17, 2023 08:04
/// Gives a Boolean condition that is true for all values represented by the
/// domain. This allows domains to be converted into program invariants.
virtual exprt to_predicate(void) const
/// Gives a Boolean condition involving expression from the set that
Copy link
Member

Choose a reason for hiding this comment

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

Gives a Boolean condition involving expressions from the given set that... ?

exprt target = value_stack.to_expression();

// This is simple if there are no restrictions:
if(scope.size() == 0)
Copy link
Member

Choose a reason for hiding this comment

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

scope.empty() ?

#include <iosfwd>

// What kind of instrumentation to add
enum class instrument_actiont
Copy link
Member

Choose a reason for hiding this comment

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

❓ Maybe this should (eventually also) consider the contracts work that @remi-delmas-3000 et al are doing? Or at least it should be considered to avoid that the design is unnecessarily incompatible with it (I doubt it is, but might be worth checking).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We are in contact and the goal is to fit with and support @remi-delmas-3000 's work. Thanks for the link though, if I didn't know about what he was doing it would be very important to find out!

martin-cs and others added 2 commits February 2, 2024 20:24
An abstract domain may contain information about variables from a calling
context which are not valid in an assertion in a different function.  This
commit changes the interface to give a limiting scope.  This is
particularly fiddly in the case of pointers to things that are out of
scope.
@martin-cs martin-cs force-pushed the feature/goto-analyzer-instrument-task branch from 1d4a86e to c0dc3a6 Compare February 2, 2024 20:24
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.

2 participants