-
Notifications
You must be signed in to change notification settings - Fork 277
Symex: shortcut the common case of whole-struct initialisation #4567
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
smowton
merged 1 commit into
diffblue:develop
from
smowton:smowton/feature/shortcut-struct-init
Apr 29, 2019
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 |
---|---|---|
|
@@ -3,7 +3,6 @@ Test.class | |
--function Test.main --show-vcc | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^\{-\d+\} symex_dynamic::dynamic_object1#2 = \{ \{ \{ "java::GenericSub" \}, NULL, 0 \} \}$ | ||
^\{-\d+\} symex_dynamic::dynamic_object1#2\.\.@Generic\.\[email protected]\.\.@class_identifier = "java::GenericSub"$ | ||
^\{-\d+\} symex_dynamic::dynamic_object1#2\.\.@Generic\.\.key = NULL$ | ||
^\{-\d+\} symex_dynamic::dynamic_object1#3\.\.@Generic\.\.x = 5$ | ||
|
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 |
---|---|---|
|
@@ -364,6 +364,51 @@ static void shift_indexed_access_to_lhs( | |
} | ||
} | ||
|
||
/// Assign a struct expression to a symbol. If \ref symex_assign_symbol was used | ||
/// then we would assign the whole symbol, before extracting its components, | ||
/// with results like `x = {1, 2}; x..field1 = x.field1; x..field2 = x.field2;` | ||
/// This abbreviates the process, directly producing | ||
/// `x..field1 = 1; x..field2 = 2;` | ||
/// \param state: goto-symex state | ||
/// \param lhs: symbol to assign (already renamed to L1) | ||
/// \param full_lhs: expression skeleton corresponding to \p lhs, to be included | ||
/// in the result trace | ||
/// \param rhs: struct expression to assign to \p lhs | ||
/// \param guard: guard conjuncts that must hold for this assignment to be made | ||
/// \param assignment_type: assignment type (see | ||
/// \ref symex_targett::assignment_typet) | ||
void goto_symext::symex_assign_from_struct( | ||
statet &state, | ||
const ssa_exprt &lhs, // L1 | ||
const exprt &full_lhs, | ||
const struct_exprt &rhs, | ||
exprt::operandst &guard, | ||
assignment_typet assignment_type) | ||
{ | ||
const struct_typet &type = to_struct_type(ns.follow(lhs.type())); | ||
const struct_union_typet::componentst &components = type.components(); | ||
PRECONDITION(rhs.operands().size() == components.size()); | ||
|
||
for(std::size_t i = 0; i < components.size(); ++i) | ||
{ | ||
const auto &comp = components[i]; | ||
exprt lhs_field = member_exprt(lhs, comp.get_name(), comp.type()); | ||
state.field_sensitivity.apply(ns, state, lhs_field, true); | ||
INVARIANT( | ||
lhs_field.id() == ID_symbol, | ||
"member of symbol should be susceptible to field-sensitivity"); | ||
|
||
const exprt &rhs_field = rhs.operands()[i]; | ||
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. I think you'd want a |
||
symex_assign_symbol( | ||
state, | ||
to_ssa_expr(lhs_field), | ||
full_lhs, | ||
rhs_field, | ||
guard, | ||
assignment_type); | ||
} | ||
} | ||
|
||
void goto_symext::symex_assign_symbol( | ||
statet &state, | ||
const ssa_exprt &lhs, // L1 | ||
|
@@ -372,6 +417,14 @@ void goto_symext::symex_assign_symbol( | |
exprt::operandst &guard, | ||
assignment_typet assignment_type) | ||
{ | ||
// Shortcut the common case of a whole-struct initializer: | ||
if(rhs.id() == ID_struct) | ||
{ | ||
symex_assign_from_struct( | ||
state, lhs, full_lhs, to_struct_expr(rhs), guard, assignment_type); | ||
return; | ||
} | ||
|
||
exprt ssa_rhs=rhs; | ||
|
||
// put assignment guard into the rhs | ||
|
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.
How about using a ranged for and an iterator over
rhs.operands()
?