Skip to content

Commit 0130d37

Browse files
committed
Add regression test on havoc_object assigning correct target
1 parent fffba8b commit 0130d37

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

regression/cbmc/havoc_choice/main.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <assert.h>
2+
#include <stdbool.h>
3+
4+
bool nondet_bool();
5+
6+
int main()
7+
{
8+
char a = 'a';
9+
char b = 'b';
10+
char c = 'c';
11+
char d = 'd';
12+
13+
char *p =
14+
nondet_bool() ? (nondet_bool() ? &a : &b) : (nondet_bool() ? &c : &d);
15+
16+
__CPROVER_havoc_object(p);
17+
18+
if(p == &a)
19+
assert(a == 'a');
20+
else
21+
assert(a == 'a');
22+
23+
if(p == &b)
24+
assert(b == 'b');
25+
else
26+
assert(b == 'b');
27+
28+
if(p == &c)
29+
assert(c == 'c');
30+
else
31+
assert(c == 'c');
32+
33+
if(p == &d)
34+
assert(d == 'd');
35+
else
36+
assert(d == 'd');
37+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
CORE new-smt-backend
2+
main.c
3+
4+
\[main\.assertion\.1\] line \d+ assertion a \=\= \'a\'\: FAILURE
5+
\[main\.assertion\.2\] line \d+ assertion a \=\= \'a\'\: SUCCESS
6+
\[main\.assertion\.3\] line \d+ assertion b \=\= \'b\'\: FAILURE
7+
\[main\.assertion\.4\] line \d+ assertion b \=\= \'b\'\: SUCCESS
8+
\[main\.assertion\.5\] line \d+ assertion c \=\= \'c\'\: FAILURE
9+
\[main\.assertion\.6\] line \d+ assertion c \=\= \'c\'\: SUCCESS
10+
\[main\.assertion\.7\] line \d+ assertion d \=\= \'d\'\: FAILURE
11+
\[main\.assertion\.8\] line \d+ assertion d \=\= \'d\'\: SUCCESS
12+
^EXIT=10$
13+
^SIGNAL=0$
14+
^VERIFICATION FAILED$
15+
--
16+
In the case where __CPROVER_havoc_object is applied to a pointer which points
17+
to one of a selection of objects, only the one object which it pointed to should
18+
be reassigned. This test is to cover the specific case where the value of the
19+
pointer is expressed using nested ternary conditional expressions.

0 commit comments

Comments
 (0)