Skip to content

Commit

Permalink
Add tests for assumption uniqueness checking
Browse files Browse the repository at this point in the history
  • Loading branch information
Remi Delmas committed Jan 21, 2025
1 parent 2d5a8b2 commit 8a32d75
Show file tree
Hide file tree
Showing 24 changed files with 377 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
void foo(int *x, int *y)
// clang-format off
__CPROVER_requires(__CPROVER_is_fresh(x, sizeof(int)))
__CPROVER_requires(*x == 0)
__CPROVER_requires(__CPROVER_pointer_equals(y, sizeof(int)) && __CPROVER_pointer_equals(y, x))
__CPROVER_assigns(*y)
__CPROVER_ensures(*y == 1)
__CPROVER_ensures(*x == 1)
// clang-format on
{
*y = 1;
}

int main()
{
int *x;
int *y;
foo(x, y);
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CORE dfcc-only
main.c
--dfcc main --enforce-contract foo
^\[__CPROVER_contracts_pointer_equals.assertion.\d+\] line \d+ __CPROVER_pointer_equals does not conflict with other predicate: FAILURE$
^EXIT=10$
^SIGNAL=0$
^VERIFICATION FAILED$
--
--
Tests that assuming the more than one pointer predicate on the same target pointer
at the same time triggers a failure.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
void foo(int *x, int *y)
// clang-format off
__CPROVER_requires(__CPROVER_is_fresh(x, sizeof(int)))
__CPROVER_requires(*x == 0)
__CPROVER_requires(__CPROVER_pointer_equals(y, x) || __CPROVER_pointer_equals(y, x))
__CPROVER_assigns(*y)
__CPROVER_ensures(*y == 1)
__CPROVER_ensures(*x == 1 || *x == 0)
// clang-format on
{
*y = 1;
}

int main()
{
int *x;
int *y;
foo(x, y);
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE dfcc-only
main.c
--dfcc main --enforce-contract foo
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFULL$
--
--
Tests that a same pointer can be the target of multiple pointer predicates as
long as they do not apply at the same time.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
void foo(int *x, int *y)
// clang-format off
__CPROVER_requires(__CPROVER_is_fresh(x, sizeof(int)))
__CPROVER_requires(*x == 0)
__CPROVER_requires(
__CPROVER_pointer_in_range_dfcc(x, y, x) &&
__CPROVER_pointer_equals(y, x))
__CPROVER_assigns(*y)
__CPROVER_ensures(*y == 1)
__CPROVER_ensures(*x == 1)
// clang-format on
{
*y = 1;
}

int main()
{
int *x;
int *y;
foo(x, y);
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CORE dfcc-only
main.c
--dfcc main --enforce-contract foo
^\[__CPROVER_contracts_pointer_in_range_dfcc.assertion.\d+\] line \d+ __CPROVER_pointer_in_range_dfcc does not conflict with other predicate: FAILURE$
^EXIT=10$
^SIGNAL=0$
^VERIFICATION FAILED$
--
--
Tests that assuming the more than one pointer predicate on the same target pointer
at the same time triggers a failure.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
void foo(int *x, int *y)
// clang-format off
__CPROVER_requires(__CPROVER_is_fresh(x, sizeof(int)))
__CPROVER_requires(*x == 0)
__CPROVER_requires(
__CPROVER_pointer_in_range_dfcc(x, y, x) &&
__CPROVER_pointer_equals(y, x))
__CPROVER_assigns(*y)
__CPROVER_ensures(*y == 1)
__CPROVER_ensures(*x == 1)
// clang-format on
{
*y = 1;
}

int main()
{
int *x;
int *y;
foo(x, y);
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE dfcc-only
main.c
--dfcc main --enforce-contract foo
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFULL$
--
--
Tests that a same pointer can be the target of multiple pointer predicates as
long as they do not apply at the same time.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
void foo(int *x, int *y)
// clang-format off
__CPROVER_requires(__CPROVER_is_fresh(x, sizeof(int)))
__CPROVER_requires(*x == 0)
__CPROVER_requires(
__CPROVER_pointer_in_range_dfcc(x, y, x) &&
__CPROVER_pointer_in_range_dfcc(x, y, x))
__CPROVER_assigns(*y)
__CPROVER_ensures(*y == 1)
__CPROVER_ensures(*x == 1)
// clang-format on
{
*y = 1;
}

int main()
{
int *x;
int *y;
foo(x, y);
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE dfcc-only
main.c
--dfcc main --enforce-contract foo
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFULL$
--
--
Tests that a same pointer can be the target of multiple pointer predicates as
long as they do not apply at the same time.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
void foo(int *x, int *y)
// clang-format off
__CPROVER_requires(__CPROVER_is_fresh(x, sizeof(int)))
__CPROVER_requires(*x == 0)
__CPROVER_requires(__CPROVER_is_fresh(y, sizeof(int)) && __CPROVER_pointer_equals(y, x))
__CPROVER_assigns(*y)
__CPROVER_ensures(*y == 1)
__CPROVER_ensures(*x == 1 || *x == 0)
// clang-format on
{
*y = 1;
}

int main()
{
int *x;
int *y;
foo(x, y);
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CORE dfcc-only
main.c
--dfcc main --enforce-contract foo
^\[__CPROVER_contracts_pointer_equals.assertion.\d+\] line \d+ __CPROVER_pointer_equals does not conflict with other predicate: FAILURE$
^EXIT=10$
^SIGNAL=0$
^VERIFICATION FAILED$
--
--
Tests that assuming the more than one pointer predicate on the same target pointer
at the same time triggers a failure.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
void foo(int *x, int *y)
// clang-format off
__CPROVER_requires(__CPROVER_is_fresh(x, sizeof(int)))
__CPROVER_requires(*x == 0)
__CPROVER_requires(__CPROVER_is_fresh(y, sizeof(int)) || __CPROVER_pointer_equals(y, x))
__CPROVER_assigns(*y)
__CPROVER_ensures(*y == 1)
__CPROVER_ensures(*x == 1 || *x == 0)
// clang-format on
{
*y = 1;
}

int main()
{
int *x;
int *y;
foo(x, y);
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE dfcc-only
main.c
--dfcc main --enforce-contract foo
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFULL$
--
--
Tests that a same pointer can be the target of multiple pointer predicates as
long as they do not apply at the same time.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
void foo(int *x, int *y)
// clang-format off
__CPROVER_requires(__CPROVER_is_fresh(x, sizeof(int)))
__CPROVER_requires(*x == 0)
__CPROVER_requires(
__CPROVER_is_fresh(y, sizeof(int)) &&
__CPROVER_pointer_in_range_dfcc(x, y, x))
__CPROVER_assigns(*y)
__CPROVER_ensures(*y == 1)
__CPROVER_ensures(*x == 1 || *x == 0)
// clang-format on
{
*y = 1;
}

int main()
{
int *x;
int *y;
foo(x, y);
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CORE dfcc-only
main.c
--dfcc main --enforce-contract foo
^\[__CPROVER_contracts_pointer_in_range_dfcc.assertion.\d+\] line \d+ __CPROVER_pointer_in_range_dfcc does not conflict with other predicate: FAILURE$
^EXIT=10$
^SIGNAL=0$
^VERIFICATION FAILED$
--
--
Tests that assuming the more than one pointer predicate on the same target pointer
at the same time triggers a failure.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
void foo(int *x, int *y)
// clang-format off
__CPROVER_requires(__CPROVER_is_fresh(x, sizeof(int)))
__CPROVER_requires(*x == 0)
__CPROVER_requires(x[SIZE-1] == 0)
__CPROVER_requires(
__CPROVER_is_fresh(y, sizeof(int)) ||
__CPROVER_pointer_in_range_dfcc(x, y, x))
__CPROVER_assigns(*y)
__CPROVER_ensures(*y == 1)
__CPROVER_ensures(*x == 1 || *x == 0)
// clang-format on
{
*y = 1;
}

int main()
{
int *x;
int *y;
foo(x, y);
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE dfcc-only
main.c
--dfcc main --enforce-contract foo
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFULL$
--
--
Tests that a same pointer can be the target of multiple pointer predicates as
long as they do not apply at the same time.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
void foo(int *x)
// clang-format off
__CPROVER_requires(
__CPROVER_is_fresh(x, sizeof(int)) && __CPROVER_is_fresh(x, sizeof(int)))
__CPROVER_assigns(*x)
__CPROVER_ensures(*x == 0)
// clang-format on
{
*x = 0;
}

int main()
{
int *x;
foo(x);
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CORE dfcc-only
main.c
--dfcc main --enforce-contract foo
^\[__CPROVER_contracts_is_fresh.assertion.\d+\] line \d+ __CPROVER_is_fresh does not conflict with other predicate: FAILURE$
^EXIT=10$
^SIGNAL=0$
^VERIFICATION FAILED$
--
--
Tests that assuming the more than one pointer predicate on the same target pointer
at the same time triggers a failure.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
void foo(int *x)
// clang-format off
__CPROVER_requires(
__CPROVER_is_fresh(x, sizeof(int)) || __CPROVER_is_fresh(x, sizeof(int)))
__CPROVER_assigns(*x)
__CPROVER_ensures(*x == 0)
// clang-format on
{
*x = 0;
}

int main()
{
int *x;
foo(x);
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
CORE dfcc-only
main.c
--dfcc main --enforce-contract foo
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFULL$
--
--
Tests that a same pointer can be the target of multiple pointer predicates as
long as they do not apply at the same time.
- `x` is fresh and inialized to 0
- `y` is equal to `x`if select is true, or fresh otherwise
- foo assigns y to 1
- x is equal to 1 if select is true, 0 otherwise
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
void foo(int *x, int *y)
// clang-format off
__CPROVER_requires(__CPROVER_is_fresh(x, sizeof(int)))
__CPROVER_requires(*x == 0)
__CPROVER_requires(
__CPROVER_pointer_in_range_dfcc(x, y, x) &&
__CPROVER_pointer_in_range_dfcc(x, y, x))
__CPROVER_assigns(*y)
__CPROVER_ensures(*y == 1)
__CPROVER_ensures(*x == 1)
// clang-format on
{
*y = 1;
}

int main()
{
int *x;
int *y;
foo(x, y);
return 0;
}
Loading

0 comments on commit 8a32d75

Please sign in to comment.