-
Notifications
You must be signed in to change notification settings - Fork 273
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
Better output of arrays in json #922
Conversation
743ce25
to
d0bfb41
Compare
|
||
\*******************************************************************/ | ||
|
||
void remove_pointer_offsets(exprt &src, symbol_exprt array_symbol) |
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.
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. |
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.
constannt->constant
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.
a unsigned -> an unsigned
{ | ||
if(idx.id()==ID_constant) | ||
{ | ||
std::string value_str=id2string(to_constant_expr(idx).get_value()); |
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.
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(); |
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.
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. |
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.
a unsigned -> an unsigned
|
||
Inputs: | ||
idx - an expression representing an index in an array | ||
out - a reference to an unsigned value |
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 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) |
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.
Doesn't ID_minus
case occur?
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.
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()); |
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.
const symbol_exprt &array_symbol
?
src/util/json_expr.cpp
Outdated
to_constant_expr( | ||
to_index_expr(src.op0()).index()).value_is_zero_string()) | ||
{ | ||
// simplify things of the form &array[0] |
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.
extra space in the comment
|
||
\*******************************************************************/ | ||
|
||
exprt simplify_array_access(const exprt &src, const namespacet &ns) |
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.
ns
is unused
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.
Looks good!
Can we have some regression tests for that? |
@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. |
83f9a3c
to
b23da64
Compare
Actually I did found examples where we have an improvement, I made a commit to add this as a regression test. |
c7b1fce
to
a308fb5
Compare
b23da64
to
74b9d95
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
@romainbrenguier could you rebase before re-review, please? |
74b9d95
to
8f192ae
Compare
@allredj @mgudemann this is now rebased |
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.
Still looks good.
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
8f192ae
to
f950ffc
Compare
This improves the output for arrays by simplifying some expressions, such as
&array[0]
andarray0[pointer_offset[array0]]
.This is related to issue diffblue/test-gen#293
and is based on PR #889(merged)