Skip to content

Commit 588a338

Browse files
author
Owen
committed
Tests for symex value-set filtering
1 parent da71ce6 commit 588a338

File tree

2 files changed

+169
-0
lines changed

2 files changed

+169
-0
lines changed
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
#include <assert.h>
2+
3+
static void noop()
4+
{
5+
}
6+
7+
int main(int argc, char **argv)
8+
{
9+
__CPROVER_assume(argc == 5);
10+
11+
int a = 2;
12+
int b = 1;
13+
int *ptr_to_a_or_b = argv[0][0] == '0' ? &a : &b;
14+
15+
// Should work (guarded by assume):
16+
int *p1 = ptr_to_a_or_b;
17+
__CPROVER_assume(p1 != &a);
18+
int c1 = *p1;
19+
20+
int *p2 = ptr_to_a_or_b;
21+
__CPROVER_assume(*p2 != a);
22+
int c2 = *p2;
23+
24+
// Should work (guarded by else):
25+
int c3 = 0;
26+
int *p3 = ptr_to_a_or_b;
27+
if(p3 == &a)
28+
{
29+
}
30+
else
31+
{
32+
c3 = *p3;
33+
}
34+
35+
int c4 = 0;
36+
int *p4 = ptr_to_a_or_b;
37+
if(*p4 == a)
38+
{
39+
}
40+
else
41+
{
42+
c4 = *p4;
43+
}
44+
45+
// Should work (guarded by if):
46+
int c5 = 0;
47+
int *p5 = ptr_to_a_or_b;
48+
if(p5 != &a)
49+
{
50+
c5 = *p5;
51+
}
52+
53+
int c6 = 0;
54+
int *p6 = ptr_to_a_or_b;
55+
if(*p6 != a)
56+
{
57+
c6 = *p6;
58+
}
59+
60+
// Should work (guarded by backward goto):
61+
int *p7 = ptr_to_a_or_b;
62+
goto check7;
63+
64+
divide7:
65+
int c7 = *p7;
66+
goto end_test7;
67+
68+
check7:
69+
__CPROVER_assume(p7 != &a);
70+
goto divide7;
71+
72+
end_test7:
73+
74+
int *p8 = ptr_to_a_or_b;
75+
goto check8;
76+
77+
divide8:
78+
int c8 = *p8;
79+
goto end_test8;
80+
81+
check8:
82+
__CPROVER_assume(*p8 != a);
83+
goto divide8;
84+
85+
end_test8:
86+
87+
// Should work (guarded by confluence):
88+
int *p9 = ptr_to_a_or_b;
89+
if(argv[1][0] == '0')
90+
__CPROVER_assume(p9 != &a);
91+
else
92+
__CPROVER_assume(p9 != &a);
93+
int c9 = *p9;
94+
95+
int *p10 = ptr_to_a_or_b;
96+
if(argv[2][0] == '0')
97+
__CPROVER_assume(*p10 != a);
98+
else
99+
__CPROVER_assume(*p10 != a);
100+
int c10 = *p10;
101+
102+
// Should work (guarded by confluence):
103+
int *p11 = ptr_to_a_or_b;
104+
__CPROVER_assume(p11 != &a);
105+
int *ptr = p11;
106+
*ptr = 1;
107+
int c11 = *p11;
108+
109+
int *p12 = ptr_to_a_or_b;
110+
__CPROVER_assume(*p12 != a);
111+
int *ptr = p12;
112+
*ptr = 1;
113+
int c12 = *p12;
114+
115+
// Should work (guarded by confluence):
116+
int *p13 = ptr_to_a_or_b;
117+
__CPROVER_assume(p13 != &a);
118+
noop();
119+
int c13 = *p13;
120+
121+
int *p14 = ptr_to_a_or_b;
122+
__CPROVER_assume(*p14 != a);
123+
noop();
124+
int c14 = *p14;
125+
126+
// Shouldn't work (unsafe as only guarded on one branch):
127+
int *p15 = ptr_to_a_or_b;
128+
if(argv[3][0] == '0')
129+
__CPROVER_assume(p15 != &a);
130+
else
131+
{
132+
}
133+
int c15 = *p15;
134+
135+
int *p16 = ptr_to_a_or_b;
136+
if(argv[4][0] == '0')
137+
__CPROVER_assume(*p16 != a);
138+
else
139+
{
140+
}
141+
int c16 = *p16;
142+
143+
assert(0);
144+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
CORE
2+
main.c
3+
--show-vcc
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
main::1::c1!0@1#. = 1
7+
main::1::c2!0@1#. = 1
8+
main::1::c3!0@1#. = 1
9+
main::1::c4!0@1#. = 1
10+
main::1::c5!0@1#. = 1
11+
main::1::c6!0@1#. = 1
12+
main::1::c7!0@1#. = 1
13+
main::1::c8!0@1#. = 1
14+
main::1::c9!0@1#. = 1
15+
main::1::c10!0@1#. = 1
16+
main::1::c11!0@1#. = 1
17+
main::1::c12!0@1#. = 1
18+
main::1::c13!0@1#. = 1
19+
main::1::c14!0@1#. = 1
20+
--
21+
^warning: ignoring
22+
main::1::c15!0@1#. = 1
23+
main::1::c16!0@1#. = 1
24+
--
25+

0 commit comments

Comments
 (0)