-
Notifications
You must be signed in to change notification settings - Fork 277
abstract_environmentt::eval rework #5644
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
martin-cs
merged 16 commits into
diffblue:develop
from
jezhiggins:abstract_environmentt-eval
Dec 15, 2020
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
c372994
index expression unit test
jezhiggins de45be5
Add eval-expression-transform to unit tests
jezhiggins 75e45c7
expand out array index unit test
jezhiggins af3eb52
Remove redundant value_set_array_abstract_object overrides
jezhiggins e62d4f1
Move index_expression evaluation into array_abstract_object
jezhiggins 8798ccc
Very simple union member access test
jezhiggins 474479c
Move member expression evaluation into struct_abstract_object
jezhiggins 405bab3
Combine member_expr and index_expr cases together
jezhiggins ba9dbf5
Removed redundant value_set_pointer_abstract_object member functions
jezhiggins a5f16cf
Move dereference evaluation into pointer_abstract_object
jezhiggins 1407cd4
Remove redundant cast
jezhiggins 7af43f3
Combine array, struct, and constant handlers
jezhiggins a983bd5
Factored out eval_operands helper function
jezhiggins c8f3e48
Clang format
jezhiggins 97b6d87
Remove abstract_objectt::read member function
jezhiggins 7ead4af
Remove redundant command line options
jezhiggins 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,15 @@ | ||
CORE | ||
union.c | ||
--variable-sensitivity --verify | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^\[main.assertion.1\] line 13 x.a==0: UNKNOWN$ | ||
^\[main.assertion.2\] line 14 x.a==1: UNKNOWN$ | ||
^\[main.assertion.3\] line 15 x.b==0: UNKNOWN$ | ||
^\[main.assertion.4\] line 16 x.b==1: UNKNOWN$ | ||
^\[main.assertion.5\] line 19 x.a==0: UNKNOWN$ | ||
^\[main.assertion.6\] line 20 x.a==1: UNKNOWN$ | ||
^\[main.assertion.7\] line 21 x.b==0: UNKNOWN$ | ||
^\[main.assertion.8\] line 22 x.b==1: UNKNOWN$ | ||
-- | ||
^warning: ignoring |
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,25 @@ | ||
#include <assert.h> | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
// Test if we can represent constant structs | ||
union union_struct { | ||
int a; | ||
int b; | ||
}; | ||
|
||
union union_struct x = {0}; | ||
x.a = 0; | ||
__CPROVER_assert(x.a == 0, "x.a==0"); | ||
__CPROVER_assert(x.a == 1, "x.a==1"); | ||
__CPROVER_assert(x.b == 0, "x.b==0"); | ||
__CPROVER_assert(x.b == 1, "x.b==1"); | ||
|
||
x.b = 1; | ||
__CPROVER_assert(x.a == 0, "x.a==0"); | ||
__CPROVER_assert(x.a == 1, "x.a==1"); | ||
__CPROVER_assert(x.b == 0, "x.b==0"); | ||
__CPROVER_assert(x.b == 1, "x.b==1"); | ||
|
||
return 0; | ||
} |
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 |
---|---|---|
|
@@ -27,6 +27,11 @@ | |
# include <iostream> | ||
#endif | ||
|
||
std::vector<abstract_object_pointert> eval_operands( | ||
const exprt &expr, | ||
const abstract_environmentt &env, | ||
const namespacet &ns); | ||
|
||
abstract_object_pointert | ||
abstract_environmentt::eval(const exprt &expr, const namespacet &ns) const | ||
{ | ||
|
@@ -51,14 +56,15 @@ abstract_environmentt::eval(const exprt &expr, const namespacet &ns) const | |
return found_symbol_value; | ||
} | ||
} | ||
else if(simplified_id == ID_member) | ||
else if( | ||
martin-cs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
simplified_id == ID_member || simplified_id == ID_index || | ||
simplified_id == ID_dereference) | ||
{ | ||
member_exprt member_expr(to_member_expr(simplified_expr)); | ||
auto access_expr = simplified_expr; | ||
auto target = eval(access_expr.operands()[0], ns); | ||
|
||
const exprt &parent = member_expr.compound(); | ||
|
||
abstract_object_pointert parent_abstract_object = eval(parent, ns); | ||
return parent_abstract_object->read(*this, member_expr, ns); | ||
return target->expression_transform( | ||
access_expr, eval_operands(access_expr, *this, ns), *this, ns); | ||
} | ||
else if(simplified_id == ID_address_of) | ||
{ | ||
|
@@ -68,35 +74,12 @@ abstract_environmentt::eval(const exprt &expr, const namespacet &ns) const | |
// Store the abstract object in the pointer | ||
return pointer_object; | ||
} | ||
else if(simplified_id == ID_dereference) | ||
{ | ||
dereference_exprt dereference(to_dereference_expr(simplified_expr)); | ||
abstract_object_pointert pointer_abstract_object = | ||
eval(dereference.pointer(), ns); | ||
|
||
return pointer_abstract_object->read(*this, nil_exprt(), ns); | ||
} | ||
else if(simplified_id == ID_index) | ||
{ | ||
index_exprt index_expr(to_index_expr(simplified_expr)); | ||
abstract_object_pointert array_abstract_object = | ||
eval(index_expr.array(), ns); | ||
|
||
return array_abstract_object->read(*this, index_expr, ns); | ||
} | ||
else if(simplified_id == ID_array) | ||
else if( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes; these are all basically the same constant case. |
||
simplified_id == ID_array || simplified_id == ID_struct || | ||
simplified_id == ID_constant) | ||
{ | ||
return abstract_object_factory(simplified_expr.type(), simplified_expr, ns); | ||
} | ||
else if(simplified_id == ID_struct) | ||
{ | ||
return abstract_object_factory(simplified_expr.type(), simplified_expr, ns); | ||
} | ||
else if(simplified_id == ID_constant) | ||
{ | ||
return abstract_object_factory( | ||
simplified_expr.type(), to_constant_expr(simplified_expr), ns); | ||
} | ||
else | ||
{ | ||
// No special handling required by the abstract environment | ||
|
@@ -448,14 +431,8 @@ abstract_object_pointert abstract_environmentt::eval_expression( | |
abstract_object_pointert eval_obj = | ||
abstract_object_factory(e.type(), ns, true); | ||
|
||
std::vector<abstract_object_pointert> operands; | ||
|
||
for(const auto &op : e.operands()) | ||
{ | ||
operands.push_back(eval(op, ns)); | ||
} | ||
|
||
return eval_obj->expression_transform(e, operands, *this, ns); | ||
return eval_obj->expression_transform( | ||
e, eval_operands(e, *this, ns), *this, ns); | ||
} | ||
|
||
void abstract_environmentt::erase(const symbol_exprt &expr) | ||
|
@@ -527,3 +504,16 @@ abstract_environmentt::gather_statistics(const namespacet &ns) const | |
} | ||
return statistics; | ||
} | ||
|
||
std::vector<abstract_object_pointert> eval_operands( | ||
const exprt &expr, | ||
const abstract_environmentt &env, | ||
const namespacet &ns) | ||
{ | ||
std::vector<abstract_object_pointert> operands; | ||
|
||
for(const auto &op : expr.operands()) | ||
operands.push_back(env.eval(op, ns)); | ||
|
||
return operands; | ||
} |
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
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
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
Oops, something went wrong.
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.
With a "most recently written" abstraction for unions it should be possible to turn about half of these into successes but for now all unknown is the best that can be done.