Skip to content

klaas' Contracts work #3769

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

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ src/.settings/*
# Visual Studio
Debug/*
Release/*
#vi(m)
*.swp

# compilation files
*.lo
Expand Down Expand Up @@ -65,6 +67,8 @@ jbmc/regression/**/tests-symex-driven-loading.log

# files stored by editors
*~
.*.swp
.*.swo

# libs downloaded by make [name]-download
minisat*/
Expand Down
21 changes: 21 additions & 0 deletions regression/ansi-c/code_contracts1/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
int foo() __CPROVER_ensures(__CPROVER_forall {
int i;
1 == 1
})
{
return 1;
}

int bar() __CPROVER_ensures(__CPROVER_forall {
int i;
1 == 1
} && __CPROVER_return_value == 1)
{
return 1;
}

int main()
{
foo();
bar();
}
8 changes: 8 additions & 0 deletions regression/ansi-c/code_contracts1/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c

^EXIT=0$
^SIGNAL=0$
--
^warning: ignoring
^CONVERSION ERROR$
3 changes: 1 addition & 2 deletions regression/contracts/function_apply_01/test.desc
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
KNOWNBUG
CORE
main.c
--apply-code-contracts
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
--
Applying code contracts currently also checks them.
5 changes: 1 addition & 4 deletions regression/contracts/function_check_01/test.desc
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
CORE
main.c
--apply-code-contracts
--check-code-contracts
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
--
--check-code-contracts not implemented yet.
--apply-code-contracts is the current name for the flag. This should be
updated as the flag changes.
7 changes: 2 additions & 5 deletions regression/contracts/function_check_04/test.desc
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
CORE
main.c
--apply-code-contracts
--check-code-contracts
^\[main.assertion.1\] .* assertion x == 0: SUCCESS$
^\[foo.1\] line 9 : FAILURE$
^\[foo.1\] .* : FAILURE$
^VERIFICATION FAILED$
--
--
--check-code-contracts not implemented yet.
--apply-code-contracts is the current name for the flag. This should be
updated as the flag changes.
11 changes: 5 additions & 6 deletions regression/contracts/function_check_05/test.desc
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
KNOWNBUG
CORE
main.c
--check-code-contracts
^\[main.assertion.1\] assertion y == 0: FAILURE$
^\[main.assertion.2\] assertion z == 1: SUCCESS$
^\[foo.1\] : SUCCESS$
^VERIFICATION SUCCESSFUL$
^\[main.assertion.1\] .* assertion y == 0: FAILURE$
^\[main.assertion.2\] .* assertion z == 1: SUCCESS$
^\[foo.1\] .* : SUCCESS$
^VERIFICATION FAILED$
--
--
Contract checking does not properly havoc function calls.
2 changes: 1 addition & 1 deletion regression/contracts/function_check_mem_01/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void foo(bar *x)
__CPROVER_requires(__CPROVER_VALID_MEM(x, sizeof(bar)))
{
x->x += 1;
return
return;
}

int main()
Expand Down
2 changes: 1 addition & 1 deletion regression/contracts/function_check_mem_01/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
KNOWNBUG
CORE
main.c
--check-code-contracts
^EXIT=0$
Expand Down
5 changes: 1 addition & 4 deletions regression/contracts/invar_check_01/test.desc
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
CORE
main.c
--apply-code-contracts
--check-code-contracts
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
--
--check-code-contracts not implemented yet.
--apply-code-contracts is the current name for the flag. This should be
updated as the flag changes.
5 changes: 1 addition & 4 deletions regression/contracts/invar_check_02/test.desc
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
CORE
main.c
--apply-code-contracts
--check-code-contracts
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
--
--check-code-contracts not implemented yet.
--apply-code-contracts is the current name for the flag. This should be
updated as the flag changes.
5 changes: 1 addition & 4 deletions regression/contracts/invar_check_03/test.desc
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
CORE
main.c
--apply-code-contracts
--check-code-contracts
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
--
--check-code-contracts not implemented yet.
--apply-code-contracts is the current name for the flag. This should be
updated as the flag changes.
7 changes: 3 additions & 4 deletions regression/contracts/invar_check_04/test.desc
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
CORE
main.c
--apply-code-contracts
--check-code-contracts
^EXIT=10$
^SIGNAL=0$
^\[main.1\] .* Loop invariant violated before entry: SUCCESS$
^\[main.2\] .* Loop invariant not preserved: SUCCESS$
^\[main.assertion.1\] .* assertion r == 0: FAILURE$
^VERIFICATION FAILED$
--
--
--check-code-contracts not implemented yet.
--apply-code-contracts is the current name for the flag. This should be
updated as the flag changes.
7 changes: 7 additions & 0 deletions regression/goto-instrument/expand-pointer-predicates1/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
int main()
{
int *x;
__CPROVER_assume(__CPROVER_points_to_valid_memory(x));
*x = 1;
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
--pointer-check --expand-pointer-predicates
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
--
7 changes: 7 additions & 0 deletions regression/goto-instrument/expand-pointer-predicates2/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
int main()
{
int *x;
__CPROVER_assume(__CPROVER_points_to_valid_memory(x, sizeof(int)));
*x = 1;
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
--pointer-check --expand-pointer-predicates
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
--
8 changes: 8 additions & 0 deletions regression/goto-instrument/expand-pointer-predicates3/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
int main()
{
int *x;
__CPROVER_assume(__CPROVER_points_to_valid_memory(x, sizeof(int)));
__CPROVER_assert(
__CPROVER_points_to_valid_memory(x, sizeof(int)), "Assert matches assume");
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
--pointer-check --expand-pointer-predicates
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
--
7 changes: 7 additions & 0 deletions regression/goto-instrument/expand-pointer-predicates4/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
int main()
{
int x;
int *y = &x;
__CPROVER_assert(__CPROVER_points_to_valid_memory(y), "Assert works on &");
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
--pointer-check --expand-pointer-predicates
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
--
19 changes: 19 additions & 0 deletions regression/goto-instrument/expand-pointer-predicates5/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
struct bar
{
int w;
int x;
int y;
int z;
};

int main()
{
struct bar s;
s.z = 5;
int *x_pointer = &(s.x);
__CPROVER_assert(
__CPROVER_points_to_valid_memory(x_pointer, 3 * sizeof(int)),
"Variable length assert");
assert(x_pointer[2] == 5);
return 0;
}
10 changes: 10 additions & 0 deletions regression/goto-instrument/expand-pointer-predicates5/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE
main.c
--pointer-check --expand-pointer-predicates
^\[main.assertion.1\] Variable length assert: SUCCESS$
^\[main.assertion.2\] assertion x_pointer\[\(signed long( long)? int\)2\] == 5: SUCCESS$
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
--
21 changes: 21 additions & 0 deletions regression/goto-instrument/expand-pointer-predicates6/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <stdlib.h>

struct my_struct
{
int *field1;
int *field2;
};

void example(struct my_struct *s)
{
s->field2 = malloc(sizeof(*(s->field2)));
}

int main()
{
struct my_struct *s;
__CPROVER_assume(__CPROVER_points_to_valid_memory(s));
example(s);
__CPROVER_assert(__CPROVER_points_to_valid_memory(s->field2), "");
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
main.c
--pointer-check --expand-pointer-predicates
^\[main.assertion.1\] : SUCCESS$
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
--
22 changes: 22 additions & 0 deletions regression/goto-instrument/expand-pointer-predicates7/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <stdlib.h>

struct my_struct
{
int *field;
};

void example(struct my_struct *s)
{
__CPROVER_assume(__CPROVER_points_to_valid_memory(s));
size_t size;
__CPROVER_assume(size == sizeof(*(s->field)));
__CPROVER_assume(__CPROVER_points_to_valid_memory(s->field, size));
int read = *(s->field);
}

int main()
{
struct my_struct *s;
example(s);
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
--pointer-check --expand-pointer-predicates
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
--
16 changes: 16 additions & 0 deletions regression/goto-instrument/expand-pointer-predicates8/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <stdlib.h>

int main()
{
int *x;
int *y;
__CPROVER_assume(__CPROVER_points_to_valid_memory(x, 2 * sizeof(int)));
__CPROVER_assume(__CPROVER_points_to_valid_memory(y, 2 * sizeof(int) - 1));
(void)(x[0]); // Should succeed
(void)(x[1]); // Should succeed
(void)(x[2]); // Should fail
(void)(x[-1]); // Should fail
(void)(y[0]); // Should succeed
(void)(y[1]); // Should fail
return 0;
}
16 changes: 16 additions & 0 deletions regression/goto-instrument/expand-pointer-predicates8/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
CORE
main.c
--pointer-check --expand-pointer-predicates
^\[main.pointer_dereference.[0-9]+\] dereference failure: dead object in x\[\(signed long( long)? int\)0\]: SUCCESS$
^\[main.pointer_dereference.[0-9]+\] dereference failure: pointer outside object bounds in x\[\(signed long( long)? int\)0\]: SUCCESS$
^\[main.pointer_dereference.[0-9]+\] dereference failure: pointer outside object bounds in x\[\(signed long( long)? int\)1\]: SUCCESS$
^\[main.pointer_dereference.[0-9]+\] dereference failure: pointer outside object bounds in x\[\(signed long( long)? int\)2\]: FAILURE$
^\[main.pointer_dereference.[0-9]+\] dereference failure: pointer outside object bounds in x\[\(signed long( long)? int\)-1\]: FAILURE$
^\[main.pointer_dereference.[0-9]+\] dereference failure: dead object in y\[\(signed long( long)? int\)0\]: SUCCESS$
^\[main.pointer_dereference.[0-9]+\] dereference failure: pointer outside object bounds in y\[\(signed long( long)? int\)0\]: SUCCESS$
^\[main.pointer_dereference.[0-9]+\] dereference failure: pointer outside object bounds in y\[\(signed long( long)? int\)1\]: FAILURE$
^EXIT=10$
^SIGNAL=0$
^VERIFICATION FAILED$
--
--
11 changes: 11 additions & 0 deletions regression/goto-instrument/expand-pointer-predicates9/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <stdlib.h>

int main()
{
char *x;
__CPROVER_assume(__CPROVER_points_to_valid_memory(x));
(void)(*x); // Should succeed
(void)(*(x + 1)); // Should fail
(void)(*(x - 1)); // Should fail
return 0;
}
12 changes: 12 additions & 0 deletions regression/goto-instrument/expand-pointer-predicates9/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CORE
main.c
--pointer-check --expand-pointer-predicates
^\[main.pointer_dereference.[0-9]+\] dereference failure: dead object in \*x: SUCCESS$
^\[main.pointer_dereference.[0-9]+\] dereference failure: pointer outside object bounds in \*x: SUCCESS$
^\[main.pointer_dereference.[0-9]+\] dereference failure: pointer outside object bounds in x\[\(signed long( long)? int\)1\]: FAILURE$
^\[main.pointer_dereference.[0-9]+\] dereference failure: pointer outside object bounds in \*\(x - \(signed long( long)? int\)1\): FAILURE$
^EXIT=10$
^SIGNAL=0$
^VERIFICATION FAILED$
--
--
Loading