Skip to content

Better output of arrays in json #922

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

Conversation

romainbrenguier
Copy link
Contributor

@romainbrenguier romainbrenguier commented May 15, 2017

This improves the output for arrays by simplifying some expressions, such as &array[0] and array0[pointer_offset[array0]].
This is related to issue diffblue/test-gen#293 and is based on PR #889 (merged)

@romainbrenguier romainbrenguier force-pushed the pull-request/arrays-in-trace branch 2 times, most recently from 743ce25 to d0bfb41 Compare June 12, 2017 07:53
@forejtv forejtv requested review from mgudemann and allredj June 12, 2017 14:03

\*******************************************************************/

void remove_pointer_offsets(exprt &src, symbol_exprt array_symbol)
Copy link
Contributor

Choose a reason for hiding this comment

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

can array_symbol be passed as a reference

simplified into a unsigned constant value.

Purpose: Simplify the expression in index as much as possible to try
to get a unsigned constannt.
Copy link
Contributor

Choose a reason for hiding this comment

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

constannt->constant

Copy link
Contributor

Choose a reason for hiding this comment

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

a unsigned -> an unsigned

{
if(idx.id()==ID_constant)
{
std::string value_str=id2string(to_constant_expr(idx).get_value());
Copy link
Contributor

Choose a reason for hiding this comment

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

value_str(id2string(...))

{
std::string value_str=id2string(to_constant_expr(idx).get_value());
mp_integer int_value=binary2integer(value_str, false);
out=int_value.to_long();
Copy link
Contributor

Choose a reason for hiding this comment

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

it is sure that there will never be an overflow?

simplified into a unsigned constant value.

Purpose: Simplify the expression in index as much as possible to try
to get a unsigned constannt.
Copy link
Contributor

Choose a reason for hiding this comment

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

a unsigned -> an unsigned


Inputs:
idx - an expression representing an index in an array
out - a reference to an unsigned value
Copy link
Contributor

Choose a reason for hiding this comment

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

I know the name of the variable speaks for itself, but could we be clearer about the fact that we write the result to out?
e.g. out - the result of the simplification?

out=int_value.to_long();
return false;
}
else if(idx.id()==ID_plus)
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't ID_minus case occur?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All examples I have seen are of the form a pointer offset address plus some constant index, but I admit I don't know whether that really covers all the possibilities.

if(src.id()==ID_index && to_index_expr(src).array().id()==ID_symbol)
{
// Case where the array is a symbol.
symbol_exprt array_symbol=to_symbol_expr(to_index_expr(src).array());
Copy link
Contributor

Choose a reason for hiding this comment

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

const symbol_exprt &array_symbol?

to_constant_expr(
to_index_expr(src.op0()).index()).value_is_zero_string())
{
// simplify things of the form &array[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

extra space in the comment


\*******************************************************************/

exprt simplify_array_access(const exprt &src, const namespacet &ns)
Copy link
Contributor

Choose a reason for hiding this comment

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

ns is unused

allredj
allredj previously approved these changes Jun 13, 2017
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

Looks good!

@allredj
Copy link
Contributor

allredj commented Jun 13, 2017

Can we have some regression tests for that?

@romainbrenguier
Copy link
Contributor Author

@allredj actually I cannot find an example where the original problem still occurs. Maybe something as been fixed in CBMC that prevent the problem we are trying to solve from happening. I will check whether this is still needed and if not we can drop this pull request.

mgudemann
mgudemann previously approved these changes Jun 13, 2017
@romainbrenguier
Copy link
Contributor Author

Actually I did found examples where we have an improvement, I made a commit to add this as a regression test.
Note that I also included the PR #1006 without which the test would fail when CBMC is compiled with sanitize option because of a memory leak solved by that PR.

allredj
allredj previously approved these changes Jun 15, 2017
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

LGTM

@mgudemann
Copy link
Contributor

@romainbrenguier could you rebase before re-review, please?

@romainbrenguier
Copy link
Contributor Author

@allredj @mgudemann this is now rebased

@romainbrenguier romainbrenguier requested review from mgudemann and removed request for mgudemann June 20, 2017 08:18
allredj
allredj previously approved these changes Jun 20, 2017
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

Still looks good.

@romainbrenguier romainbrenguier requested review from mgudemann and removed request for mgudemann June 21, 2017 14:13
mgudemann
mgudemann previously approved these changes Jun 21, 2017
We simplifying these expression so that these pointers appear correctly
in the trace in json.
This is related to issue diffblue/test-gen#21

Includes improvements in json_expr.cpp following review of PR#922
We simplify expressions containing array accesses before producing a
json representation of the trace.
This commit also adds comments on the functions in the cpp files

Includes improvements in json_goto_trace.cpp following review of PR#922
@romainbrenguier romainbrenguier dismissed stale reviews from mgudemann and allredj via f950ffc June 21, 2017 19:40
@romainbrenguier romainbrenguier force-pushed the pull-request/arrays-in-trace branch from 8f192ae to f950ffc Compare June 21, 2017 19:40
@romainbrenguier romainbrenguier merged commit 05875e1 into diffblue:test-gen-support Jun 22, 2017
@romainbrenguier romainbrenguier deleted the pull-request/arrays-in-trace branch June 22, 2017 16:28
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.

3 participants