-
Notifications
You must be signed in to change notification settings - Fork 273
added __CPROVER_havoc(...) #1449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are too many assertions in just one regression test. What do you think if we split them into different regressions tests? I can see here three different regression tests, i.e., havoc primitive, arrays and structs data types.