Skip to content

Commit 1cc4bc2

Browse files
authored
Merge pull request #8576 from remi-delmas-3000/contracts-is-fresh-demonic
CONTRACTS: separation checks using nondet demonic variable
2 parents 3d79560 + d490670 commit 1cc4bc2

File tree

10 files changed

+210
-186
lines changed

10 files changed

+210
-186
lines changed
+7-27
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,15 @@
1-
#include <assert.h>
2-
#include <stdbool.h>
3-
#include <stdlib.h>
4-
5-
int z;
6-
7-
// clang-format off
8-
int foo(int *x, int *y)
9-
__CPROVER_assigns(z, *x)
10-
__CPROVER_requires(
11-
__CPROVER_is_fresh(x, sizeof(int)) &&
12-
*x > 0 &&
13-
*x < 4)
14-
__CPROVER_ensures(
15-
__CPROVER_is_fresh(y, sizeof(int)) &&
16-
!__CPROVER_is_fresh(x, sizeof(int)) &&
17-
x != NULL &&
18-
x != y &&
19-
__CPROVER_return_value == *x + 5)
1+
int *foo()
2+
// clang-format off
3+
__CPROVER_ensures(__CPROVER_is_fresh(__CPROVER_return_value, sizeof(int)))
204
// clang-format on
215
{
22-
*x = *x + 4;
23-
y = malloc(sizeof(*y));
24-
*y = *x;
25-
z = *y;
26-
return (*x + 5);
6+
int *ret = malloc(sizeof(int));
7+
__CPROVER_assume(ret);
8+
return ret;
279
}
2810

2911
int main()
3012
{
31-
int n = 4;
32-
n = foo(&n, &n);
33-
assert(!(n < 4));
13+
foo();
3414
return 0;
3515
}

Diff for: regression/contracts-dfcc/test_aliasing_ensure/test.desc

-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ main.c
44
^EXIT=0$
55
^SIGNAL=0$
66
\[foo.postcondition.\d+\].*Check ensures clause of contract contract::foo for function foo: SUCCESS$
7-
\[foo.assigns.\d+\].*Check that \*x is assignable: SUCCESS
8-
\[foo.assigns.\d+\].*Check that \*y is assignable: SUCCESS
9-
\[foo.assigns.\d+\].*Check that z is assignable: SUCCESS
10-
\[main.assertion.\d+\].*assertion \!\(n \< 4\): SUCCESS
117
^VERIFICATION SUCCESSFUL$
128
--
139
--

Diff for: regression/contracts-dfcc/test_scalar_memory_enforce/main.c

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ int foo(int *x)
2121
ptr_ok(x))
2222
__CPROVER_ensures(
2323
!ptr_ok(x) &&
24-
!__CPROVER_is_fresh(x, sizeof(int)) &&
2524
return_ok(__CPROVER_return_value, x))
2625
// clang-format on
2726
{

0 commit comments

Comments
 (0)