Skip to content

A new implementation for assigns clauses #6377

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
Oct 4, 2021

Conversation

feliperodri
Copy link
Collaborator

@feliperodri feliperodri commented Oct 1, 2021

This change is a complete rewrite of the assigns clause, based on a new formalization. Each assigns clause target is modeled as a "conditional address range" (CAR) that is an address range guarded by a validity condition.

  • 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).
  • n/a 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 do not review aws Bugs or features of importance to AWS CBMC users Code Contracts Function and loop contracts labels Oct 1, 2021
@SaswatPadhi SaswatPadhi force-pushed the car branch 5 times, most recently from 3808cdd to fdfbece Compare October 3, 2021 03:11
@codecov
Copy link

codecov bot commented Oct 3, 2021

Codecov Report

Merging #6377 (a307396) into develop (3f48b6e) will increase coverage by 0.00%.
The diff coverage is 97.35%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #6377   +/-   ##
========================================
  Coverage    75.90%   75.91%           
========================================
  Files         1517     1517           
  Lines       163893   163936   +43     
========================================
+ Hits        124406   124451   +45     
+ Misses       39487    39485    -2     
Impacted Files Coverage Δ
src/ansi-c/ansi_c_convert_type.cpp 78.78% <ø> (-0.21%) ⬇️
src/goto-instrument/contracts/contracts.h 100.00% <ø> (ø)
src/goto-instrument/contracts/utils.h 100.00% <ø> (ø)
src/goto-instrument/havoc_utils.h 100.00% <ø> (ø)
src/ansi-c/c_typecheck_base.cpp 78.24% <50.00%> (-0.52%) ⬇️
src/goto-instrument/contracts/assigns.cpp 98.73% <98.55%> (+0.29%) ⬆️
src/goto-instrument/contracts/assigns.h 100.00% <100.00%> (ø)
src/goto-instrument/contracts/contracts.cpp 95.91% <100.00%> (+0.13%) ⬆️
src/goto-instrument/contracts/utils.cpp 91.83% <100.00%> (+0.72%) ⬆️
src/util/simplify_expr_int.cpp 84.14% <0.00%> (+0.10%) ⬆️
... and 3 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 a03d382...a307396. Read the comment docs.

@SaswatPadhi SaswatPadhi changed the title Conditional Address Ranges (CARs) A new implementation for assigns clauses Oct 3, 2021
@SaswatPadhi SaswatPadhi marked this pull request as ready for review October 3, 2021 06:03
@SaswatPadhi SaswatPadhi changed the title A new implementation for assigns clauses A new implementation for assigns clauses [depends-on: #6371] Oct 3, 2021
@SaswatPadhi
Copy link
Contributor

Depends on #6371 -- must be merged after that is merged.

Comment on lines 654 to 655
// TODO: Fix this.
// The CAR snapshot should be made only once at the beginning.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This comment should map to a GitHub issue and we should add the link here

TODO: <link>

Comment on lines 94 to 95
// FIXME: Refactor these checks out to a common function that can be
// used both in compilation and instrumentation stages
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This should map to a GitHub issue, and we should add the link here.

Copy link
Collaborator Author

@feliperodri feliperodri left a comment

Choose a reason for hiding this comment

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

@SaswatPadhi only minor comments. Approved.

@@ -13,7 +13,7 @@ Author: Daniel Kroening, [email protected]

#include <util/c_types.h>
#include <util/config.h>
#include <util/expr_util.h>
#include <util/std_code.h>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why do we need this include?

Comment on lines +25 to +26
// FIXME: Refactor these checks out to a common function that can be
// used both in compilation and instrumentation stages
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Are we tracking this request somewhere?

Comment on lines +32 to +33
typecast_exprt::conditional_cast(arg, pointer_type(char_type())),
pointer_offset(arg)},
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Shall we add a comment about why do we cast this to char here?

@@ -8,3 +8,5 @@ main.c
--
Check that Elvis operator expressions of form '(cond ? *if_true : *if_false)'
are supported in assigns clauses.

BUG: `is_lvalue` in goto is not consistent with `target.get_bool(ID_C_lvalue)`.
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 should open a GitHub issue for this bug. This is outside the contract implementation.

This change is a complete rewrite of the assigns clause, based on a new
formalization. Each assigns clause target represents a "conditional
address range" (CAR) that an address range guarded by a validity
constraint.

In this commit we also add support for __CPROVER_POINTER_OBJECT
expressions in assigns clauses.
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.

Approving on behalf of @feliperodri.

@SaswatPadhi SaswatPadhi changed the title A new implementation for assigns clauses [depends-on: #6371] A new implementation for assigns clauses Oct 4, 2021
@@ -3,21 +3,18 @@ main.c
--enforce-contract foo --enforce-contract bar --enforce-contract baz _ --pointer-primitive-check
^EXIT=10$
^SIGNAL=0$
^\[bar.\d+\] line \d+ Check that \*a is assignable: SUCCESS$
^\[bar.\d+\] line \d+ Check that POINTER_OBJECT\(\(void \*\)a\) is assignable: SUCCESS$
Copy link
Member

Choose a reason for hiding this comment

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

The new message is a downgrade in terms of user experience.

// clang-format off
__CPROVER_requires(b->size == 5)
__CPROVER_assigns(__CPROVER_POINTER_OBJECT(b->buf))
__CPROVER_assigns(__CPROVER_POINTER_OBJECT(value))
Copy link
Member

Choose a reason for hiding this comment

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

This overloaded use of __CPROVER_POINTER_OBJECT will confuse. I would advise to use a different identifier.

@@ -53,10 +53,10 @@ class havoc_if_validt : public havoc_utilst
/// over all dereferenced pointer expressions *(pexpr_1), *(pexpr_2), ...
/// found in the AST of `expr`.
///
/// \param expr The expression that contains dereferences to be validated
/// \param ns The namespace that defines all symbols appearing in `expr`
/// \param expr: The expression that contains dereferences to be validated.
Copy link
Contributor

Choose a reason for hiding this comment

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

Extra docs are always nice :-) But the addition of ':' following parameter names is unusual and adds a bit of noise to the diff. Not a blocking comment at all - just an observation to be aware of.

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought that's the convention in this repo (variable name followed by a colon in the docs). I saw that in several files, so changed this accordingly.
For example: https://github.com/diffblue/cbmc/blob/48893287099cb5780302fe9dc415eb6888354fd6/src/util/expr_cast.h

@feliperodri feliperodri merged commit 7e7d047 into diffblue:develop Oct 4, 2021
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 aws-high bugfix Code Contracts Function and loop contracts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants