File tree Expand file tree Collapse file tree 4 files changed +73
-0
lines changed
regression/contracts/assigns_enforce_functions_in_contracts Expand file tree Collapse file tree 4 files changed +73
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include "utility.h"
2
+ #include <stdbool.h>
3
+ #include <stdlib.h>
4
+
5
+ int foo (int * x ) __CPROVER_requires (s2n_result_is_ok (validity3 (x )))
6
+ __CPROVER_assigns (* x ) __CPROVER_ensures (
7
+ __CPROVER_return_value == * x + 5 && s2n_result_is_ok (validity3 (x )))
8
+ {
9
+ * x = * x + 0 ;
10
+ return * x + 5 ;
11
+ }
Original file line number Diff line number Diff line change
1
+ #include "header.h"
2
+
3
+ int main ()
4
+ {
5
+ int * n = malloc (sizeof (* n ));
6
+ * n = foo (n );
7
+
8
+ return 0 ;
9
+ }
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
+ This test checks whether verification succeeds when requires and ensures
10
+ contain functions.
11
+
12
+ Note: We still don't check for function purity, i.e.,
13
+ functions in contracts must only work as predicates.
Original file line number Diff line number Diff line change
1
+ #include <stdbool.h>
2
+ #include <stdlib.h>
3
+
4
+ /* Function return code */
5
+ #define S2N_SUCCESS 0
6
+ #define S2N_FAILURE -1
7
+
8
+ /* A value which indicates the outcome of a function */
9
+ typedef struct
10
+ {
11
+ int __error_signal ;
12
+ } s2n_result ;
13
+
14
+ #define S2N_RESULT s2n_result
15
+ #define S2N_RESULT_OK ((s2n_result){S2N_SUCCESS})
16
+ #define S2N_RESULT_ERROR ((s2n_result){S2N_FAILURE})
17
+
18
+ bool s2n_result_is_ok (s2n_result result )
19
+ {
20
+ return result .__error_signal == S2N_SUCCESS ;
21
+ }
22
+
23
+ bool validity1 (int * x )
24
+ {
25
+ return (x > 0 );
26
+ }
27
+
28
+ bool validity2 (int * x )
29
+ {
30
+ return (x == 0 );
31
+ }
32
+
33
+ S2N_RESULT validity3 (int * x )
34
+ {
35
+ if (x == NULL )
36
+ return S2N_RESULT_ERROR ;
37
+ if (!validity1 (x ))
38
+ return S2N_RESULT_ERROR ;
39
+ return S2N_RESULT_OK ;
40
+ }
You can’t perform that action at this time.
0 commit comments