Skip to content

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

Merged

Conversation

mgudemann
Copy link
Contributor

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.

@mgudemann mgudemann force-pushed the fix/bytecode_args_write_from_stack branch from 84cc74b to b3e4296 Compare May 23, 2017 07:32
@mgudemann mgudemann requested review from smowton and tautschnig May 23, 2017 07:33
@mgudemann
Copy link
Contributor Author

still needs a regression test for ?astore

Copy link
Contributor

@smowton smowton left a 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]+
Copy link
Contributor

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

Copy link
Contributor Author

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$
$
Copy link
Contributor

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)

Copy link
Contributor Author

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)
Copy link
Contributor

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.

Copy link
Contributor Author

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());
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Collaborator

@tautschnig tautschnig left a 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++)
Copy link
Collaborator

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?

Copy link
Contributor Author

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);
Copy link
Collaborator

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++)
Copy link
Collaborator

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);
Copy link
Collaborator

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);
Copy link
Collaborator

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);

Copy link
Contributor Author

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));
Copy link
Collaborator

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++)
Copy link
Collaborator

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);
Copy link
Collaborator

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++)
Copy link
Collaborator

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);
Copy link
Collaborator

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);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@mgudemann mgudemann force-pushed the fix/bytecode_args_write_from_stack branch from b3e4296 to ed0b3b1 Compare May 24, 2017 16:27
@mgudemann mgudemann force-pushed the fix/bytecode_args_write_from_stack branch from ed0b3b1 to 8b4e2e9 Compare May 24, 2017 16:40
Copy link
Contributor

@smowton smowton left a 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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use .get_component_name()

Copy link
Collaborator

@tautschnig tautschnig left a 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
@mgudemann mgudemann force-pushed the fix/bytecode_args_write_from_stack branch from 3e52f89 to 0ce085f Compare May 25, 2017 13:25
@mgudemann
Copy link
Contributor Author

all fixed

@kroening kroening merged commit a71dfb5 into diffblue:master Jun 18, 2017
@mgudemann mgudemann deleted the fix/bytecode_args_write_from_stack branch July 1, 2018 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants