Skip to content

Commit bdebfb6

Browse files
klaaskarkhaz
klaas
authored andcommitted
Reworks checking of code contracts
This commit completes the work started in the previous commit by revising the existing contract-handling code into the new pass --check-code-contracts, which first applies all contracts and then checks them. By applying the contracts before checking begins, this checks the relative correctness of each function/loop with respect to the functions called by/loops contained in it. Since there can be no infinite sequence of nested functions/loops, these relative correctness results together imply the correctness of the overall program. We take this approach rather than checking entirely without using contracts because it allows significant reuse of results --- a function that is called many times only needs to be checked once, and all of its invocations will be abstracted out by the contract application.
1 parent 40bd1b3 commit bdebfb6

File tree

12 files changed

+382
-67
lines changed

12 files changed

+382
-67
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ src/.settings/*
1919
# Visual Studio
2020
Debug/*
2121
Release/*
22+
#vi(m)
23+
*.swp
2224

2325
# compilation files
2426
*.lo
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
CORE
22
main.c
3-
--apply-code-contracts
3+
--check-code-contracts
44
^EXIT=0$
55
^SIGNAL=0$
66
^VERIFICATION SUCCESSFUL$
77
--
88
--
9-
--check-code-contracts not implemented yet.
10-
--apply-code-contracts is the current name for the flag. This should be
11-
updated as the flag changes.
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
KNOWNBUG
1+
CORE
22
main.c
3-
--apply-code-contracts
3+
--check-code-contracts
44
^\[main.assertion.1\] .* assertion x == 0: SUCCESS$
5-
^\[foo.1\] line 9 : FAILURE$
5+
^\[foo.1\] .* : FAILURE$
66
^VERIFICATION FAILED$
77
--
88
--
9-
--check-code-contracts not implemented yet.
10-
--apply-code-contracts is the current name for the flag. This should be
11-
updated as the flag changes.

regression/contracts/function_check_mem_01/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void foo(bar *x)
3333
__CPROVER_requires(__CPROVER_VALID_MEM(x, sizeof(bar)))
3434
{
3535
x->x += 1;
36-
return
36+
return;
3737
}
3838

3939
int main()

regression/contracts/function_check_mem_01/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
CORE
22
main.c
33
--check-code-contracts
44
^EXIT=0$
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
KNOWNBUG
1+
CORE
22
main.c
3-
--apply-code-contracts
3+
--check-code-contracts
44
^EXIT=0$
55
^SIGNAL=0$
66
^VERIFICATION SUCCESSFUL$
77
--
88
--
9-
--check-code-contracts not implemented yet.
10-
--apply-code-contracts is the current name for the flag. This should be
11-
updated as the flag changes.
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
KNOWNBUG
1+
CORE
22
main.c
3-
--apply-code-contracts
3+
--check-code-contracts
44
^EXIT=0$
55
^SIGNAL=0$
66
^VERIFICATION SUCCESSFUL$
77
--
88
--
9-
--check-code-contracts not implemented yet.
10-
--apply-code-contracts is the current name for the flag. This should be
11-
updated as the flag changes.
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
KNOWNBUG
1+
CORE
22
main.c
3-
--apply-code-contracts
3+
--check-code-contracts
44
^EXIT=0$
55
^SIGNAL=0$
66
^VERIFICATION SUCCESSFUL$
77
--
88
--
9-
--check-code-contracts not implemented yet.
10-
--apply-code-contracts is the current name for the flag. This should be
11-
updated as the flag changes.
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
KNOWNBUG
1+
CORE
22
main.c
3-
--apply-code-contracts
3+
--check-code-contracts
4+
^EXIT=10$
5+
^SIGNAL=0$
46
^\[main.1\] .* Loop invariant violated before entry: SUCCESS$
57
^\[main.2\] .* Loop invariant not preserved: SUCCESS$
68
^\[main.assertion.1\] .* assertion r == 0: FAILURE$
79
^VERIFICATION FAILED$
810
--
911
--
10-
--check-code-contracts not implemented yet.
11-
--apply-code-contracts is the current name for the flag. This should be
12-
updated as the flag changes.

0 commit comments

Comments
 (0)