Skip to content

Commit 78ee23e

Browse files
committed
Add extra regression test for set_field.
1 parent 1a50c53 commit 78ee23e

File tree

2 files changed

+64
-0
lines changed

2 files changed

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

0 commit comments

Comments
 (0)