Skip to content

Commit

Permalink
CONTRACTS: separation checks using nondet demonic variable
Browse files Browse the repository at this point in the history
- Replace bool array indexed by object ID with nondet
  demonic variable to implement separation checks.
- Fix test: don't use is fresh under negation

format
  • Loading branch information
Remi Delmas committed Jan 25, 2025
1 parent 3d79560 commit d490670
Show file tree
Hide file tree
Showing 10 changed files with 210 additions and 186 deletions.
34 changes: 7 additions & 27 deletions regression/contracts-dfcc/test_aliasing_ensure/main.c
Original file line number Diff line number Diff line change
@@ -1,35 +1,15 @@
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>

int z;

// clang-format off
int foo(int *x, int *y)
__CPROVER_assigns(z, *x)
__CPROVER_requires(
__CPROVER_is_fresh(x, sizeof(int)) &&
*x > 0 &&
*x < 4)
__CPROVER_ensures(
__CPROVER_is_fresh(y, sizeof(int)) &&
!__CPROVER_is_fresh(x, sizeof(int)) &&
x != NULL &&
x != y &&
__CPROVER_return_value == *x + 5)
int *foo()
// clang-format off
__CPROVER_ensures(__CPROVER_is_fresh(__CPROVER_return_value, sizeof(int)))
// clang-format on
{
*x = *x + 4;
y = malloc(sizeof(*y));
*y = *x;
z = *y;
return (*x + 5);
int *ret = malloc(sizeof(int));
__CPROVER_assume(ret);
return ret;
}

int main()
{
int n = 4;
n = foo(&n, &n);
assert(!(n < 4));
foo();
return 0;
}
4 changes: 0 additions & 4 deletions regression/contracts-dfcc/test_aliasing_ensure/test.desc
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ main.c
^EXIT=0$
^SIGNAL=0$
\[foo.postcondition.\d+\].*Check ensures clause of contract contract::foo for function foo: SUCCESS$
\[foo.assigns.\d+\].*Check that \*x is assignable: SUCCESS
\[foo.assigns.\d+\].*Check that \*y is assignable: SUCCESS
\[foo.assigns.\d+\].*Check that z is assignable: SUCCESS
\[main.assertion.\d+\].*assertion \!\(n \< 4\): SUCCESS
^VERIFICATION SUCCESSFUL$
--
--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ int foo(int *x)
ptr_ok(x))
__CPROVER_ensures(
!ptr_ok(x) &&
!__CPROVER_is_fresh(x, sizeof(int)) &&
return_ok(__CPROVER_return_value, x))
// clang-format on
{
Expand Down
Loading

0 comments on commit d490670

Please sign in to comment.