1
+ #include <assert.h>
2
+
3
+ struct S {
4
+ short x [3 ];
5
+ char c ;
6
+ };
7
+
8
+ int main (void ) {
9
+ __CPROVER_field_decl_local ("f" , (char ) 0 );
10
+
11
+ struct S s ;
12
+
13
+ // Setting the struct recursively set all its fields
14
+ __CPROVER_set_field (& s , "f" , 1 );
15
+
16
+ assert (__CPROVER_get_field (& s .x [0 ], "f" ) == 1 );
17
+ assert (__CPROVER_get_field (& s .x [1 ], "f" ) == 1 );
18
+ assert (__CPROVER_get_field (& s .x [2 ], "f" ) == 1 );
19
+ assert (__CPROVER_get_field (& s .c , "f" ) == 1 );
20
+ assert (__CPROVER_get_field (& s , "f" ) == 1 );
21
+
22
+ // Setting the struct recursively set all its fields
23
+ __CPROVER_set_field (& s , "f" , 0 );
24
+
25
+ assert (__CPROVER_get_field (& s .x [0 ], "f" ) == 0 );
26
+ assert (__CPROVER_get_field (& s .x [1 ], "f" ) == 0 );
27
+ assert (__CPROVER_get_field (& s .x [2 ], "f" ) == 0 );
28
+ assert (__CPROVER_get_field (& s .c , "f" ) == 0 );
29
+ assert (__CPROVER_get_field (& s , "f" ) == 0 );
30
+
31
+ // Setting a field of the struct changes its values ad after aggregation the whole struct value
32
+ __CPROVER_set_field (& s .x [1 ], "f" , 2 );
33
+
34
+ assert (__CPROVER_get_field (& s .x [0 ], "f" ) == 0 );
35
+ assert (__CPROVER_get_field (& s .x [1 ], "f" ) == 2 );
36
+ assert (__CPROVER_get_field (& s .x [2 ], "f" ) == 0 );
37
+ assert (__CPROVER_get_field (& s .c , "f" ) == 0 );
38
+ assert (__CPROVER_get_field (& s , "f" ) == 2 );
39
+
40
+ // Rest shadow memory
41
+ __CPROVER_set_field (& s , "f" , 0 );
42
+
43
+ // Changing ONLY first cell of S array at field x by using offset with pointer arithmetics
44
+ short * p = ((short * )& s ) + 1 ;
45
+ __CPROVER_set_field (p , "f" , 3 );
46
+
47
+ assert (__CPROVER_get_field (& s .x [0 ], "f" ) == 0 );
48
+ assert (__CPROVER_get_field (& s .x [1 ], "f" ) == 3 );
49
+ assert (__CPROVER_get_field (& s .x [2 ], "f" ) == 0 );
50
+ assert (__CPROVER_get_field (& s .c , "f" ) == 0 );
51
+ assert (__CPROVER_get_field (& s , "f" ) == 3 );
52
+
53
+ return 0 ;
54
+ }
0 commit comments