File tree Expand file tree Collapse file tree 2 files changed +70
-0
lines changed
regression/contracts/assigns_enforce_havoc_object Expand file tree Collapse file tree 2 files changed +70
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include <assert.h>
2
+ #include <stdlib.h>
3
+
4
+ int x = 0 ;
5
+ typedef struct stc
6
+ {
7
+ int i ;
8
+ int j ;
9
+ } stc ;
10
+
11
+ typedef struct stb
12
+ {
13
+ stc * c ;
14
+ } stb ;
15
+
16
+ typedef struct sta
17
+ {
18
+ union {
19
+ stb * b ;
20
+ int i ;
21
+ int j ;
22
+ } u ;
23
+ } sta ;
24
+
25
+ int nondet_int ();
26
+
27
+ void bar (sta * a )
28
+ {
29
+ if (nondet_bool ())
30
+ return ;
31
+ __CPROVER_havoc_object (a -> u .b -> c );
32
+ return ;
33
+ }
34
+
35
+ void foo (sta * a1 , sta * a2 )
36
+ __CPROVER_assigns (__CPROVER_POINTER_OBJECT (a1 - > u .b - > c ))
37
+ {
38
+ bar (a1 );
39
+ bar (a2 );
40
+ return ;
41
+ }
42
+
43
+ sta * allocate_sta ()
44
+ {
45
+ stc * c = malloc (sizeof (* c ));
46
+ stb * b = malloc (sizeof (* b ));
47
+ sta * a = malloc (sizeof (* a ));
48
+ b -> c = c ;
49
+ a -> u .b = b ;
50
+ return a ;
51
+ }
52
+
53
+ int main ()
54
+ {
55
+ sta * a1 = allocate_sta ();
56
+ sta * a2 = allocate_sta ();
57
+ foo (a1 , a2 );
58
+ return 0 ;
59
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ main.c
3
+ --enforce-contract foo
4
+ ^EXIT=10$
5
+ ^SIGNAL=0$
6
+ ^\[bar.\d+\] line \d+ Check that POINTER_OBJECT\(\(void \*\)a->u\.b->c\) is assignable: SUCCESS$
7
+ ^\[bar.\d+\] line \d+ Check that POINTER_OBJECT\(\(void \*\)a->u\.b->c\) is assignable: FAILURE$
8
+ ^VERIFICATION FAILED$
9
+ --
10
+ --
11
+ Checks that __CPROVER_havoc_object(x) is detected as a write to POINTER_OBJECT(x).
You can’t perform that action at this time.
0 commit comments