File tree Expand file tree Collapse file tree 27 files changed +488
-16
lines changed
history-pointer-enforce-01
history-pointer-enforce-02
history-pointer-enforce-03
history-pointer-enforce-04
history-pointer-enforce-05
history-pointer-enforce-06
history-pointer-enforce-07
history-pointer-replace-01
history-pointer-replace-02
history-pointer-replace-03 Expand file tree Collapse file tree 27 files changed +488
-16
lines changed Original file line number Diff line number Diff line change
1
+ void foo (int * x ) __CPROVER_assigns (* x )
2
+ __CPROVER_ensures (* x == __CPROVER_old (* x ) + 5 )
3
+ {
4
+ * x = * x + 5 ;
5
+ }
6
+
7
+ int main ()
8
+ {
9
+ int n ;
10
+ foo (& n );
11
+
12
+ return 0 ;
13
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ main.c
3
+ --enforce-all-contracts
4
+ ^EXIT=0$
5
+ ^SIGNAL=0$
6
+ ^VERIFICATION SUCCESSFUL$
7
+ --
8
+ --
9
+ Verification:
10
+ This test checks that history variables are supported for parameters of the
11
+ the function under test. By using the --enforce-all-contracts flag,
12
+ the post-condition (which contains the history variable) is asserted.
13
+ In this case, this assertion should pass.
Original file line number Diff line number Diff line change
1
+ void foo (int * x ) __CPROVER_assigns (* x )
2
+ __CPROVER_ensures (* x < __CPROVER_old (* x ) + 5 )
3
+ {
4
+ * x = * x + 5 ;
5
+ }
6
+
7
+ int main ()
8
+ {
9
+ int n ;
10
+ foo (& n );
11
+
12
+ return 0 ;
13
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ main.c
3
+ --enforce-all-contracts
4
+ ^EXIT=10$
5
+ ^SIGNAL=0$
6
+ ^VERIFICATION FAILED$
7
+ --
8
+ --
9
+ Verification:
10
+ This test checks that history variables are supported for parameters of the
11
+ the function under test. By using the --enforce-all-contracts flag,
12
+ the post-condition (which contains the history variable) is asserted.
13
+ In this case, this assertion should fail.
Original file line number Diff line number Diff line change
1
+ void foo (int * x ) __CPROVER_assigns (* x )
2
+ __CPROVER_requires (* x > 0 && * x < __INT_MAX__ - 5 ) __CPROVER_ensures (
3
+ * x >= __CPROVER_old (* x ) + 4 && * x <= __CPROVER_old (* x ) + 6 )
4
+ {
5
+ * x = * x + 5 ;
6
+ }
7
+
8
+ int main ()
9
+ {
10
+ int n ;
11
+ foo (& n );
12
+
13
+ return 0 ;
14
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ main.c
3
+ --enforce-all-contracts _ --trace
4
+ ^EXIT=0$
5
+ ^SIGNAL=0$
6
+ ^VERIFICATION SUCCESSFUL$
7
+ --
8
+ --
9
+ Verification:
10
+ This test checks that history variables are supported in the case where a
11
+ history variable is referred to multiple times within an ensures clause.
12
+ By using the --enforce-all-contracts flag, the post-condition (which contains
13
+ the history variable) is asserted. In this case, this assertion should pass.
Original file line number Diff line number Diff line change
1
+ void foo (int * x , int * y ) __CPROVER_assigns (* x , * y )
2
+ __CPROVER_ensures (* x == __CPROVER_old (* y ) + 1 && * y == __CPROVER_old (* x ) + 2 )
3
+ {
4
+ int x_initial = * x ;
5
+ * x = * y + 1 ;
6
+ * y = x_initial + 2 ;
7
+ }
8
+
9
+ int main ()
10
+ {
11
+ int x , y ;
12
+ foo (& x , & y );
13
+
14
+ return 0 ;
15
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ main.c
3
+ --enforce-all-contracts
4
+ ^EXIT=0$
5
+ ^SIGNAL=0$
6
+ ^VERIFICATION SUCCESSFUL$
7
+ --
8
+ --
9
+ Verification:
10
+ This test checks that history variables are supported in the case where the
11
+ function under test has multiple parameters. By using the
12
+ --enforce-all-contracts flag, the post-condition (which contains the history
13
+ variables) is asserted. In this case, this assertion should pass.
Original file line number Diff line number Diff line change
1
+ void foo (int * x , int * y ) __CPROVER_assigns (* x , * y )
2
+ __CPROVER_ensures (* x == __CPROVER_old (* x ) + 2 || * y == __CPROVER_old (* y ) + 3 )
3
+ {
4
+ * x = * x + 1 ;
5
+ * y = * y + 2 ;
6
+ }
7
+
8
+ int main ()
9
+ {
10
+ int x , y ;
11
+ foo (& x , & y );
12
+
13
+ return 0 ;
14
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ main.c
3
+ --enforce-all-contracts
4
+ ^EXIT=10$
5
+ ^SIGNAL=0$
6
+ ^VERIFICATION FAILED$
7
+ --
8
+ --
9
+ Verification:
10
+ This test checks that history variables are supported in the case where the
11
+ function under test has multiple parameters. By using the
12
+ --enforce-all-contracts flag, the post-condition (which contains the history
13
+ variables) is asserted. In this case, this assertion should fail.
Original file line number Diff line number Diff line change
1
+ #include <assert.h>
2
+
3
+ void foo (int * x ) __CPROVER_assigns (* x )
4
+ __CPROVER_ensures (* x == __CPROVER_old (* x ) + 5 )
5
+ {
6
+ assert (__CPROVER_old (* x ) == * x );
7
+ * x = * x + 5 ;
8
+ }
9
+
10
+ int main ()
11
+ {
12
+ int n ;
13
+ foo (& n );
14
+
15
+ return 0 ;
16
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ main.c
3
+ --enforce-all-contracts
4
+ ^EXIT=10$
5
+ ^SIGNAL=0$
6
+ ^VERIFICATION FAILED$
7
+ --
8
+ --
9
+ Verification:
10
+ This test checks that history variables are not supported when referred to from
11
+ a function body. In such a case, verification should fail.
Original file line number Diff line number Diff line change
1
+ void foo (int * x ) __CPROVER_assigns (* x )
2
+ __CPROVER_ensures (* x == __CPROVER_old (* y ) + 5 )
3
+ {
4
+ * x = * x + 5 ;
5
+ }
6
+
7
+ int main ()
8
+ {
9
+ int n ;
10
+ foo (& n );
11
+
12
+ return 0 ;
13
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ main.c
3
+ --enforce-all-contracts
4
+ ^EXIT=1$
5
+ ^SIGNAL=0$
6
+ ^CONVERSION ERROR$
7
+ --
8
+ --
9
+ Verification:
10
+ This test checks that history variables may only be used with existing
11
+ symbols. In other words, including a new symbol as part of __CPROVER_old()
12
+ is not alowed. In such a case, the program should not parse and there
13
+ should be a conversion error.
Original file line number Diff line number Diff line change
1
+ #include <assert.h>
2
+
3
+ void foo (int * x ) __CPROVER_assigns (* x ) __CPROVER_requires (* x > 0 )
4
+ __CPROVER_ensures (* x == __CPROVER_old (* x ) + 2 )
5
+ {
6
+ * x = * x + 2 ;
7
+ }
8
+
9
+ int main ()
10
+ {
11
+ int n ;
12
+ __CPROVER_assume (n > 0 && n < __INT_MAX__ - 2 );
13
+ foo (& n );
14
+
15
+ assert (n > 2 );
16
+
17
+ return 0 ;
18
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ main.c
3
+ --replace-all-calls-with-contracts
4
+ ^EXIT=0$
5
+ ^SIGNAL=0$
6
+ ^VERIFICATION SUCCESSFUL$
7
+ --
8
+ --
9
+ Verification:
10
+ This test checks that history variables are supported with the use of the
11
+ --replace-all-calls-with-contracts flag. In this case, the post-condition
12
+ (which contains the history variable) becomes an assumption. We then manually
13
+ assert this assumption. For this test, the assertion should succeed.
Original file line number Diff line number Diff line change
1
+ #include <assert.h>
2
+
3
+ void foo (int * x ) __CPROVER_assigns (* x ) __CPROVER_requires (* x == 0 )
4
+ __CPROVER_ensures (* x > __CPROVER_old (* x ) + 2 )
5
+ {
6
+ * x = * x + 2 ;
7
+ }
8
+
9
+ int main ()
10
+ {
11
+ int n = 0 ;
12
+ foo (& n );
13
+
14
+ assert (n > 2 );
15
+
16
+ return 0 ;
17
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ main.c
3
+ --replace-all-calls-with-contracts
4
+ ^EXIT=0$
5
+ ^SIGNAL=0$
6
+ ^VERIFICATION SUCCESSFUL$
7
+ --
8
+ --
9
+ Verification:
10
+ This test checks that history variables are supported with the use of the
11
+ --replace-all-calls-with-contracts flag. In this case, the post-condition
12
+ (which contains the history variable) becomes an assumption. We then manually
13
+ assert this assumption. For this test, the assertion should succeed.
Original file line number Diff line number Diff line change
1
+ #include <assert.h>
2
+
3
+ void foo (int * x ) __CPROVER_assigns (* x )
4
+ __CPROVER_requires (* x == __CPROVER_old (* x ))
5
+ __CPROVER_ensures (* x == __CPROVER_old (* x ) + 2 )
6
+ {
7
+ * x = * x + 2 ;
8
+ }
9
+
10
+ int main ()
11
+ {
12
+ int n = 0 ;
13
+ foo (& n );
14
+
15
+ assert (n == 2 );
16
+
17
+ return 0 ;
18
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ main.c
3
+ --replace-all-calls-with-contracts
4
+ ^EXIT=10$
5
+ ^SIGNAL=0$
6
+ ^VERIFICATION FAILED$
7
+ --
8
+ --
9
+ Verification:
10
+ This test checks that history variables cannot be used as part of the
11
+ pre-condition contract. In this case, verification should fail.
Original file line number Diff line number Diff line change @@ -2575,6 +2575,20 @@ exprt c_typecheck_baset::do_special_functions(
2575
2575
2576
2576
return std::move (ok_expr);
2577
2577
}
2578
+ else if (identifier == CPROVER_PREFIX " old" )
2579
+ {
2580
+ if (expr.arguments ().size () != 1 )
2581
+ {
2582
+ error ().source_location = f_op.source_location ();
2583
+ error () << identifier << " expects one operands" << eom;
2584
+ throw 0 ;
2585
+ }
2586
+
2587
+ old_exprt old_expr (ID_old, expr.arguments ()[0 ]);
2588
+ old_expr.add_source_location () = source_location;
2589
+
2590
+ return std::move (old_expr);
2591
+ }
2578
2592
else if (identifier==CPROVER_PREFIX " isinff" ||
2579
2593
identifier==CPROVER_PREFIX " isinfd" ||
2580
2594
identifier==CPROVER_PREFIX " isinfld" ||
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ __CPROVER_size_t __CPROVER_zero_string_length(const void *);
12
12
__CPROVER_size_t __CPROVER_buffer_size (const void * );
13
13
__CPROVER_bool __CPROVER_r_ok (const void * , __CPROVER_size_t );
14
14
__CPROVER_bool __CPROVER_w_ok (const void * , __CPROVER_size_t );
15
+ void __CPROVER_old (const void * );
15
16
16
17
// bitvector analysis
17
18
__CPROVER_bool __CPROVER_get_flag (const void * , const char * );
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ __CPROVER_size_t __CPROVER_zero_string_length(const void *);
35
35
__CPROVER_size_t __CPROVER_buffer_size (const void * );
36
36
__CPROVER_bool __CPROVER_r_ok (const void * , __CPROVER_size_t );
37
37
__CPROVER_bool __CPROVER_w_ok (const void * , __CPROVER_size_t );
38
+ void __CPROVER_old (const void * );
38
39
39
40
#if 0
40
41
__CPROVER_bool __CPROVER_equal ();
You can’t perform that action at this time.
0 commit comments