-
Notifications
You must be signed in to change notification settings - Fork 273
Fix/bytecode args write from stack #951
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
Fix/bytecode args write from stack #951
Conversation
84cc74b
to
b3e4296
Compare
still needs a regression test for |
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.
Broadly looks good, a few specific suggestions, plus perhaps you could factor the stack backup routines into something like backup_stack_aliases (some_predicate)
where the predicate differs by instruction type, looking for field or symbol or local variable references as appropriate?
@@ -4,7 +4,7 @@ test.class | |||
dead anonlocal::1i | |||
dead anonlocal::2i | |||
dead anonlocal::3a | |||
dead new_tmp0 | |||
dead new_tmp[0123456789]+ |
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.
You can use [0-9] for this
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.
done
^EXIT=10$ | ||
^SIGNAL=0$ | ||
^.*assertion at file stack_test.java line 5 function.*: FAILURE$ | ||
$ |
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.
Remove this (it will match any line)
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.
done
{ | ||
const exprt &stack_entry=stack[i]; | ||
exprt entry=stack_entry; | ||
if(entry.id()==ID_typecast) |
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.
Probably while
. I certainly try not to introduce double casts, but there are probably still places where they get introduced.
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.
done
const exprt &stack_entry=stack[i]; | ||
if(stack_entry.id()!=ID_member) | ||
continue; | ||
const exprt tmp_var=tmp_variable("stack_field", stack_entry.type()); |
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.
Might as well compare the member names like the symbol comparison above?
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.
is done in the refactored code
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.
Lots of mostly minor comments, but having repeated the very same comments 4-5 times makes me feel very uneasy about this. It seems a refactoring would be necessary.
block.add_source_location()=i_it->source_location; | ||
// search dereferences on stack, replace all with values in temporary | ||
// variables | ||
for(size_t i=0; i<stack.size(); i++) |
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.
Is there any reason not to use a ranged for here?
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.
I refactored the code, please have a look
{ | ||
const exprt tmp_var= | ||
tmp_variable("stack_static_field", stack_entry.type()); | ||
code_assignt assign=code_assignt(tmp_var, stack_entry); |
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.
As above
|
||
exprt toassign=op[0]; | ||
if('a'==statement[0] && toassign.type()!=var.type()) | ||
toassign=typecast_exprt(toassign, var.type()); | ||
|
||
c=code_assignt(var, toassign); | ||
code_blockt block; | ||
for(size_t i=0; i<stack.size(); i++) |
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.
Again: ranged for?
{ | ||
const exprt tmp_var= | ||
tmp_variable("stack_store", stack_entry.type()); | ||
code_assignt assign=code_assignt(tmp_var, stack_entry); |
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.
As above: code_assignt assign(tmp_var, stack_entry);
} | ||
} | ||
|
||
code_assignt assign=code_assignt(var, toassign); |
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.
code_assignt assign(var, toassign);
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.
done
const exprt tmp_var= | ||
tmp_variable("stack_iinc_lvar", java_int_type()); | ||
block.copy_to_operands( | ||
code_assignt(tmp_var, locvar)); |
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.
Make that code more similar to the above by introducing a temporary variable, which will then also have the source location assigned.
code_blockt block; | ||
block.add_source_location()=i_it->source_location; | ||
// create temporary variables to save values of member exprts | ||
for(size_t i=0; i<stack.size(); i++) |
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.
Ranged for
if(stack_entry.id()!=ID_member) | ||
continue; | ||
const exprt tmp_var=tmp_variable("stack_field", stack_entry.type()); | ||
code_assignt assign=code_assignt(tmp_var, stack_entry); |
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.
As above
code_blockt block; | ||
block.add_source_location()=i_it->source_location; | ||
// create temporary variables to save values of static fields | ||
for(size_t i=0; i<stack.size(); i++) |
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.
Ranged for
continue; | ||
const exprt tmp_var= | ||
tmp_variable("stack_astore", stack_entry.type()); | ||
code_assignt assign=code_assignt(tmp_var, stack_entry); |
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.
code assignt assign(tmp_var, stack_entry);
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.
done
b3e4296
to
ed0b3b1
Compare
ed0b3b1
to
8b4e2e9
Compare
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.
LGTM
stack_entry.id()==ID_member) | ||
{ | ||
const irep_idt &entry_id= | ||
to_member_expr(stack_entry).get(ID_component_name); |
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.
Use .get_component_name()
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.
Just one minor API-usage suggestion, but otherwise looks good. Thanks a lot for all the refactoring!
concerned bytecode instructions: - iinc - pustatic - putfield - ?store - ?astore
3e52f89
to
0ce085f
Compare
all fixed |
alternative to #931 ; as suggested by @smowton instead of adding temporary variables for load operations, this adds temporary variables on store, and also filters for types of operations and variable names.