Skip to content

Commit 618b074

Browse files
author
Owen
committed
Add tests for symex evaluating simple pointer comparisons
At time of writing, develop fails on the following lines of the test: Failed test.desc lines: test::1::unconditionally_reachable_1[^\s]+ = \(goto_symex::\\guard[^\s]+ \? 7 : test::1::unconditionally_reachable_1[^\s]+\)$ [FAILED] test::1::unconditionally_reachable_7[^\s]+ = \(goto_symex::\\guard[^\s]+ \? 7 : test::1::unconditionally_reachable_7[^\s]+\)$ [FAILED] test::1::unconditionally_reachable_11[^\s]+ = \(goto_symex::\\guard[^\s]+ \? 7 : test::1::unconditionally_reachable_11[^\s]+\)$ [FAILED] test::1::unreachable_6[^\s]+ = 7$ [FAILED] test::1::unreachable_14[^\s]+ = 7$ [FAILED]
1 parent 2fa372e commit 618b074

File tree

2 files changed

+106
-0
lines changed
  • regression/cbmc/symex_should_evaluate_simple_pointer_conditions

2 files changed

+106
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#include <assert.h>
2+
3+
static void noop() { }
4+
5+
int test(int nondet_int) {
6+
int a = 1, b = 2, c = 3;
7+
8+
// Symex knows the value of ptr_to_a, so it should be able to evaluate simple
9+
// conditions involving it.
10+
int *ptr_to_a = &a;
11+
12+
int unconditionally_reachable_1;
13+
if(ptr_to_a == &a)
14+
unconditionally_reachable_1 = 7;
15+
16+
int unreachable_2;
17+
if(ptr_to_a == &c)
18+
unreachable_2 = 7;
19+
20+
int unconditionally_reachable_3;
21+
if(ptr_to_a != &c)
22+
unconditionally_reachable_3 = 7;
23+
24+
int unreachable_4;
25+
if(ptr_to_a != &a)
26+
unreachable_4 = 7;
27+
28+
// Symex can't tell what ptr_to_a_or_b points to, but we can tell that it
29+
// doesn't point to some things
30+
int *ptr_to_a_or_b = nondet_int == 0 ? &a : &b;
31+
32+
int possibly_reachable_5;
33+
if(ptr_to_a_or_b == &a)
34+
possibly_reachable_5 = 7;
35+
36+
int unreachable_6;
37+
if(ptr_to_a_or_b == &c)
38+
unreachable_6 = 7;
39+
40+
int unconditionally_reachable_7;
41+
if(ptr_to_a_or_b != &c)
42+
unconditionally_reachable_7 = 7;
43+
44+
int possibly_reachable_8;
45+
if(ptr_to_a_or_b != &a)
46+
possibly_reachable_8 = 7;
47+
48+
// We should also be able to do all of the above in compound expressions which
49+
// use logical operators like AND, OR and NOT.
50+
51+
int unconditionally_reachable_9;
52+
if(!(ptr_to_a == &c))
53+
unconditionally_reachable_9 = 7;
54+
55+
int unreachable_10;
56+
if(!(ptr_to_a == &a))
57+
unreachable_10 = 7;
58+
59+
int unconditionally_reachable_11;
60+
if(!(ptr_to_a_or_b == &c))
61+
unconditionally_reachable_11 = 7;
62+
63+
int possibly_reachable_12;
64+
if(!(ptr_to_a_or_b == &a))
65+
possibly_reachable_12 = 7;
66+
67+
int unconditionally_reachable_13;
68+
if((ptr_to_a == &a && c == 3) || c == 0)
69+
unconditionally_reachable_13 = 7;
70+
71+
int unreachable_14;
72+
if((ptr_to_a_or_b == &c && c == 3) || c == 0)
73+
unreachable_14 = 7;
74+
75+
assert(0);
76+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
CORE
2+
test.c
3+
--function test --show-vcc
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
test::1::unconditionally_reachable_1[^\s]+ = 7$
7+
test::1::unconditionally_reachable_3[^\s]+ = 7$
8+
test::1::unconditionally_reachable_7[^\s]+ = 7$
9+
test::1::unconditionally_reachable_9[^\s]+ = 7$
10+
test::1::unconditionally_reachable_11[^\s]+ = 7$
11+
test::1::unconditionally_reachable_13[^\s]+ = 7$
12+
test::1::possibly_reachable_5[^\s]+ = \(goto_symex::\\guard[^\s]+ \? 7 : test::1::possibly_reachable_5[^\s]+\)$
13+
test::1::possibly_reachable_8[^\s]+ = \(goto_symex::\\guard[^\s]+ \? 7 : test::1::possibly_reachable_8[^\s]+\)$
14+
test::1::possibly_reachable_12[^\s]+ = \(goto_symex::\\guard[^\s]+ \? 7 : test::1::possibly_reachable_12[^\s]+\)$
15+
--
16+
test::1::unconditionally_reachable_1[^\s]+ = \(goto_symex::\\guard[^\s]+ \? 7 : test::1::unconditionally_reachable_1[^\s]+\)$
17+
test::1::unconditionally_reachable_3[^\s]+ = \(goto_symex::\\guard[^\s]+ \? 7 : test::1::unconditionally_reachable_3[^\s]+\)$
18+
test::1::unconditionally_reachable_7[^\s]+ = \(goto_symex::\\guard[^\s]+ \? 7 : test::1::unconditionally_reachable_7[^\s]+\)$
19+
test::1::unconditionally_reachable_9[^\s]+ = \(goto_symex::\\guard[^\s]+ \? 7 : test::1::unconditionally_reachable_9[^\s]+\)$
20+
test::1::unconditionally_reachable_11[^\s]+ = \(goto_symex::\\guard[^\s]+ \? 7 : test::1::unconditionally_reachable_11[^\s]+\)$
21+
test::1::unconditionally_reachable_13[^\s]+ = \(goto_symex::\\guard[^\s]+ \? 7 : test::1::unconditionally_reachable_13[^\s]+\)$
22+
test::1::unreachable_2[^\s]+ = 7$
23+
test::1::unreachable_4[^\s]+ = 7$
24+
test::1::unreachable_6[^\s]+ = 7$
25+
test::1::unreachable_10[^\s]+ = 7$
26+
test::1::unreachable_14[^\s]+ = 7$
27+
^warning: ignoring
28+
--
29+
Pointer comparisons will be resolved in symex by a mixture of constant
30+
propagation and value-set filtering

0 commit comments

Comments
 (0)