forked from diffblue/cbmc
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Daniel Kroening
committed
Oct 10, 2017
1 parent
8118efa
commit beac327
Showing
7 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
int main() | ||
{ | ||
int i=0; | ||
__CPROVER_havoc_object(&i); | ||
__CPROVER_assert(i==0, "i==0"); // should fail | ||
|
||
int array[10]; | ||
for(i=0; i<10; i++) array[i]=i; | ||
|
||
__CPROVER_havoc_object(array); | ||
__CPROVER_assert(array[3]==3, "array[3]"); // should fail | ||
|
||
struct { int i, j; } some_struct = { 1, 2 }; | ||
__CPROVER_havoc_object(&some_struct.j); | ||
__CPROVER_assert(some_struct.i==1, "struct i"); // should fail | ||
__CPROVER_assert(some_struct.j==2, "struct j"); // should fail | ||
|
||
// now conditional | ||
_Bool c; | ||
int *p=c?&i:&some_struct.i; | ||
i=20; | ||
some_struct.i=30; | ||
__CPROVER_havoc_object(p); | ||
if(c) | ||
{ | ||
__CPROVER_assert(i==20, "i==20 (A)"); // should fail | ||
__CPROVER_assert(some_struct.i==30, "some_struct.i==30 (A)"); // should pass | ||
} | ||
else | ||
{ | ||
__CPROVER_assert(i==20, "i==20 (B)"); // should pass | ||
__CPROVER_assert(some_struct.i==30, "some_struct.i==30 (B)"); // should fail | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CORE | ||
main.c | ||
|
||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
^VERIFICATION FAILED$ | ||
^\*\* 6 of 8 failed.*$ | ||
-- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,10 +17,67 @@ Author: Daniel Kroening, [email protected] | |
#include <util/rename.h> | ||
#include <util/base_type.h> | ||
#include <util/std_expr.h> | ||
#include <util/std_code.h> | ||
#include <util/byte_operators.h> | ||
|
||
#include <util/c_types.h> | ||
|
||
void goto_symext::havoc_rec( | ||
statet &state, | ||
const guardt &guard, | ||
const exprt &dest) | ||
{ | ||
if(dest.id()==ID_symbol) | ||
{ | ||
exprt lhs; | ||
|
||
if(guard.is_true()) | ||
lhs=dest; | ||
else | ||
lhs=if_exprt( | ||
guard.as_expr(), dest, exprt("NULL-object", dest.type())); | ||
|
||
code_assignt assignment; | ||
assignment.lhs()=lhs; | ||
assignment.rhs()=side_effect_expr_nondett(dest.type()); | ||
|
||
symex_assign(state, assignment); | ||
} | ||
else if(dest.id()==ID_byte_extract_little_endian || | ||
dest.id()==ID_byte_extract_big_endian) | ||
{ | ||
havoc_rec(state, guard, to_byte_extract_expr(dest).op()); | ||
} | ||
else if(dest.id()==ID_if) | ||
{ | ||
const if_exprt &if_expr=to_if_expr(dest); | ||
|
||
guardt guard_t=state.guard; | ||
guard_t.add(if_expr.cond()); | ||
havoc_rec(state, guard_t, if_expr.true_case()); | ||
|
||
guardt guard_f=state.guard; | ||
guard_f.add(not_exprt(if_expr.cond())); | ||
havoc_rec(state, guard_f, if_expr.false_case()); | ||
} | ||
else if(dest.id()==ID_typecast) | ||
{ | ||
havoc_rec(state, guard, to_typecast_expr(dest).op()); | ||
} | ||
else if(dest.id()==ID_index) | ||
{ | ||
havoc_rec(state, guard, to_index_expr(dest).array()); | ||
} | ||
else if(dest.id()==ID_member) | ||
{ | ||
havoc_rec(state, guard, to_member_expr(dest).struct_op()); | ||
} | ||
else | ||
{ | ||
// consider printing a warning | ||
} | ||
} | ||
|
||
void goto_symext::symex_other( | ||
const goto_functionst &goto_functions, | ||
statet &state) | ||
|
@@ -213,6 +270,17 @@ void goto_symext::symex_other( | |
{ | ||
target.memory_barrier(state.guard.as_expr(), state.source); | ||
} | ||
else if(statement==ID_havoc_object) | ||
{ | ||
DATA_INVARIANT(code.operands().size()==1, | ||
"havoc_object must have one operand"); | ||
|
||
// we need to add dereferencing for the first operand | ||
exprt object=dereference_exprt(code.op0(), empty_typet()); | ||
clean_expr(object, state, true); | ||
|
||
havoc_rec(state, guardt(), object); | ||
} | ||
else | ||
throw "unexpected statement: "+id2string(statement); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters