Skip to content

Commit f868847

Browse files
author
Enrico Steffinlongo
authored
Merge pull request #7831 from thomasspriggs/tas/fix_havoc_guards
Fix havoc guards
2 parents cdea666 + e546b83 commit f868847

File tree

3 files changed

+63
-3
lines changed

3 files changed

+63
-3
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.

src/goto-symex/symex_other.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ void goto_symext::havoc_rec(
4646
{
4747
const if_exprt &if_expr=to_if_expr(dest);
4848

49-
guardt guard_t=state.guard;
49+
guardt guard_t = guard;
5050
guard_t.add(if_expr.cond());
5151
havoc_rec(state, guard_t, if_expr.true_case());
5252

53-
guardt guard_f=state.guard;
53+
guardt guard_f = guard;
5454
guard_f.add(not_exprt(if_expr.cond()));
5555
havoc_rec(state, guard_f, if_expr.false_case());
5656
}
@@ -68,7 +68,11 @@ void goto_symext::havoc_rec(
6868
}
6969
else
7070
{
71-
// consider printing a warning
71+
INVARIANT_WITH_DIAGNOSTICS(
72+
false,
73+
"Attempted to symex havoc applied to unsupported expression",
74+
state.source.pc->code().pretty(),
75+
dest.pretty());
7276
}
7377
}
7478

0 commit comments

Comments
 (0)