File tree 12 files changed +268
-77
lines changed
invar_assigns_alias_analysis
src/goto-instrument/contracts 12 files changed +268
-77
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 2
2
3
3
int main ()
4
4
{
5
- int r ;
6
- __CPROVER_assume (r >= 0 );
7
- while (r > 0 )
8
- __CPROVER_assigns () __CPROVER_loop_invariant (r >= 0 )
5
+ while (1 == 1 )
6
+ __CPROVER_assigns () __CPROVER_loop_invariant (1 == 1 )
9
7
{
10
- r -- ;
11
8
}
12
- assert (r == 0 );
13
-
14
- return 0 ;
15
9
}
Original file line number Diff line number Diff line change 5
5
^SIGNAL=0$
6
6
^\[main.1\] .* Check loop invariant before entry: SUCCESS$
7
7
^\[main.2\] .* Check that loop invariant is preserved: SUCCESS$
8
- ^\[main.assertion.1\] .* assertion r == 0: SUCCESS$
9
8
^VERIFICATION SUCCESSFUL$
10
9
--
11
10
--
Original file line number Diff line number Diff line change 3
3
--apply-loop-contracts
4
4
^EXIT=0$
5
5
^SIGNAL=0$
6
- ^\[main.1\] .* Check loop invariant before entry: SUCCESS$
7
- ^\[main.2\] .* Check that loop invariant is preserved: SUCCESS$
8
- ^\[main.3\] .* Check decreases clause on loop iteration: SUCCESS$
9
- ^\[main.assertion.1\] .* assertion r1 == 0: SUCCESS$
10
- ^\[main.4\] .* Check loop invariant before entry: SUCCESS$
11
- ^\[main.5\] .* Check that loop invariant is preserved: SUCCESS$
12
- ^\[main.6\] .* Check decreases clause on loop iteration: SUCCESS$
13
- ^\[main.assertion.2\] .* assertion r2 == 0: SUCCESS$
6
+ ^\[main.\d+\] .* Check loop invariant before entry: SUCCESS$
7
+ ^\[main.\d+\] .* Check that loop invariant is preserved: SUCCESS$
8
+ ^\[main.\d+\] .* Check decreases clause on loop iteration: SUCCESS$
9
+ ^\[main.assertion.\d+\] .* assertion r1 == 0: SUCCESS$
10
+ ^\[main.\d+\] .* Check loop invariant before entry: SUCCESS$
11
+ ^\[main.\d+\] .* Check that s2 is assignable: SUCCESS$
12
+ ^\[main.\d+\] .* Check that r2 is assignable: SUCCESS$
13
+ ^\[main.\d+\] .* Check that loop invariant is preserved: SUCCESS$
14
+ ^\[main.\d+\] .* Check decreases clause on loop iteration: SUCCESS$
15
+ ^\[main.assertion.\d+\] .* assertion r2 == 0: SUCCESS$
14
16
^VERIFICATION SUCCESSFUL$
15
17
--
16
18
--
Original file line number Diff line number Diff line change
1
+ #include <assert.h>
2
+ #include <stdlib.h>
3
+
4
+ #define SIZE 8
5
+
6
+ struct blob
7
+ {
8
+ char * data ;
9
+ };
10
+
11
+ void main ()
12
+ {
13
+ struct blob * b = malloc (sizeof (struct blob ));
14
+ b -> data = malloc (SIZE );
15
+
16
+ b -> data [5 ] = 0 ;
17
+ for (unsigned i = 0 ; i < SIZE ; i ++ )
18
+ // clang-format off
19
+ __CPROVER_assigns (i , __CPROVER_POINTER_OBJECT (b -> data ))
20
+ __CPROVER_loop_invariant (i <= SIZE )
21
+ // clang-format on
22
+ {
23
+ b -> data [i ] = 1 ;
24
+ }
25
+
26
+ assert (b -> data [5 ] == 0 );
27
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ main.c
3
+ --apply-loop-contracts
4
+ ^EXIT=10$
5
+ ^SIGNAL=0$
6
+ ^\[main.\d+\] .* Check loop invariant before entry: SUCCESS$
7
+ ^\[main.\d+\] .* Check that i is assignable: SUCCESS$
8
+ ^\[main.\d+\] .* Check that b->data\[(.*)i\] is assignable: SUCCESS$
9
+ ^\[main.\d+\] .* Check that loop invariant is preserved: SUCCESS$
10
+ ^\[main.assertion.\d+\] .* assertion b->data\[5\] == 0: FAILURE$
11
+ ^VERIFICATION FAILED$
12
+ --
13
+ --
14
+ This test (taken from #6021) shows the need for assigns clauses on loops.
15
+ The alias analysis in this case returns `unknown`,
16
+ and so we must manually annotate an assigns clause on the loop.
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ void main()
16
16
b -> data [5 ] = 0 ;
17
17
for (unsigned i = 0 ; i < SIZE ; i ++ )
18
18
// clang-format off
19
- __CPROVER_assigns (b -> data )
19
+ __CPROVER_assigns (i , b -> data [ i ] )
20
20
__CPROVER_loop_invariant (i <= SIZE )
21
21
// clang-format on
22
22
{
Original file line number Diff line number Diff line change
1
+ CORE
2
+ main.c
3
+ --apply-loop-contracts
4
+ ^EXIT=10$
5
+ ^SIGNAL=0$
6
+ ^\[main.\d+\] .* Check loop invariant before entry: SUCCESS$
7
+ ^\[main.\d+\] .* Check that i is assignable: SUCCESS$
8
+ ^\[main.\d+\] .* Check that b->data\[(.*)i\] is assignable: FAILURE$
9
+ ^\[main.\d+\] .* Check that loop invariant is preserved: SUCCESS$
10
+ ^\[main.assertion.\d+\] .* assertion b->data\[5\] == 0: FAILURE$
11
+ ^VERIFICATION FAILED$
12
+ --
13
+ --
14
+ This test (taken from #6021) shows the need for assigns clauses on loops.
15
+ The alias analysis in this case returns `unknown`,
16
+ and so we must manually annotate an assigns clause on the loop.
17
+
18
+ Note that the annotated assigns clause in this case is an underapproximation,
19
+ per the current semantics of the assigns clause -- it must model ALL memory
20
+ being assigned to by the loop, not just a single symbolic iteration.
Original file line number Diff line number Diff line change
1
+ #include <assert.h>
2
+ #include <stdlib.h>
3
+
4
+ #define SIZE 8
5
+
6
+ struct blob
7
+ {
8
+ char * data ;
9
+ };
10
+
11
+ void main ()
12
+ {
13
+ struct blob * b = malloc (sizeof (struct blob ));
14
+ b -> data = malloc (SIZE );
15
+
16
+ b -> data [5 ] = 0 ;
17
+ for (unsigned i = 0 ; i < SIZE ; i ++ )
18
+ // clang-format off
19
+ __CPROVER_assigns (__CPROVER_POINTER_OBJECT (b -> data ))
20
+ __CPROVER_loop_invariant (i <= SIZE )
21
+ // clang-format on
22
+ {
23
+ b -> data [i ] = 1 ;
24
+ }
25
+
26
+ assert (b -> data [5 ] == 0 );
27
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ main.c
3
+ --apply-loop-contracts
4
+ ^EXIT=10$
5
+ ^SIGNAL=0$
6
+ ^\[main.\d+\] .* Check loop invariant before entry: SUCCESS$
7
+ ^\[main.\d+\] .* Check that i is assignable: FAILURE$
8
+ ^\[main.\d+\] .* Check that b->data\[(.*)i\] is assignable: SUCCESS$
9
+ ^\[main.\d+\] .* Check that loop invariant is preserved: SUCCESS$
10
+ ^\[main.assertion.\d+\] .* assertion b->data\[5\] == 0: SUCCESS$
11
+ ^VERIFICATION FAILED$
12
+ --
13
+ --
14
+ This test (taken from #6021) shows the need for assigns clauses on loops.
15
+ The alias analysis in this case returns `unknown`,
16
+ and so we must manually annotate an assigns clause on the loop.
17
+
18
+ Note that the annotated assigns clause in this case is an underapproximation,
19
+ because `i` is also assigned in the loop and should be marked as assignable.
You can’t perform that action at this time.
0 commit comments