-
Notifications
You must be signed in to change notification settings - Fork 277
use optional for unknown pointer offset sizes #2137
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
2a7f009
to
aac7dd7
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.
This looks good to me. I'd be curious to know whether there is any change in performance (positive or negative) for some of this code is called a lot.
if(offset_bits.has_value()) | ||
offset = to_range_spect(*offset_bits); | ||
else | ||
offset = -1; |
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.
Nit pick: use ? :
as above instead of the if ... else
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.
Merged with next branch
src/analyses/goto_rw.cpp
Outdated
if(subtype_bits.has_value()) | ||
sub_size = to_range_spect(*subtype_bits); | ||
else | ||
sub_size = -1; |
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 ? :
as above.
src/analyses/goto_rw.cpp
Outdated
if(subtype_bits.has_value()) | ||
sub_size = to_range_spect(*subtype_bits); | ||
else | ||
sub_size = -1; |
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 ? :
as above.
src/analyses/goto_rw.cpp
Outdated
if(subtype_bits.has_value()) | ||
sub_size = to_range_spect(*subtype_bits); | ||
else | ||
sub_size = -1; |
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 ? :
as 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.
Merged with next branch.
{ | ||
range_spect size = to_range_spect(*param_bits); | ||
gen(from, identifier, 0, size); | ||
} |
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.
No, this should invoke gen
even when the size cannot be determined (using -1
as a value of size
is well-defined).
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.
fixed.
src/goto-programs/vcd_goto_trace.cpp
Outdated
|
||
if(width>=0) | ||
return std::string(integer2size_t(width), 'x'); | ||
if(width.has_value() && *width >= 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.
The *width >= 0
is trivially true and should be removed.
aac7dd7
to
4964eb2
Compare
Performance: I would expect a very minor positive effect (the comparison with of an mp_integer with -1 is mildly elaborate). |
4964eb2
to
2621da2
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.
Mostly nitpicks but at least a couple of mistakes to fix
src/analyses/goto_rw.cpp
Outdated
to_range_spect(pointer_offset_bits(vector_type.subtype(), ns)); | ||
auto subtype_bits = pointer_offset_bits(vector_type.subtype(), ns); | ||
|
||
sub_size = subtype_bits.has_value()?to_range_spect(*subtype_bits):-1; |
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.
?: op spacing (also below)
src/pointer-analysis/value_set.cpp
Outdated
if(comp_offset>op1_offset) | ||
if(!comp_offset.has_value()) | ||
continue; | ||
else if(comp_offset > op1_offset) |
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.
*comp_offset
?
if(s<=0) | ||
auto s = pointer_offset_bits(src, ns); | ||
|
||
if(!s.has_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.
|| !*s
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 had pondered this one as well, but it's actually ok as the loop simply turns into a no-op.
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.
Ah true, though I suspect the original author intended to skip set-up for the loop in that case. That means the only proper error is the !=
vs. ==
problem below.
src/util/pointer_offset_size.cpp
Outdated
return member_bits; | ||
auto member_bits = pointer_offset_bits(comp.type(), ns); | ||
if(!member_bits.has_value()) | ||
return optionalt<mp_integer>(); |
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 use {}
as a shorthand if you prefer
src/util/simplify_expr.cpp
Outdated
// no arrays of non-byte sized objects | ||
assert(el_size%8==0); | ||
mp_integer el_bytes=el_size/8; | ||
DATA_INVARIANT(*el_size>0, "no arrays of zero-sized objects"); |
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.
Rephrase as a "should" statement for clarity when printed as an error dump (as written it's not clear whether we're forbidding or complaining that no such array was found)
src/util/simplify_expr.cpp
Outdated
@@ -2038,7 +2033,7 @@ bool simplify_exprt::simplify_byte_update(byte_update_exprt &expr) | |||
const typet &op_type=ns.follow(root.type()); | |||
|
|||
// size must be known | |||
if(val_size<=0) | |||
if(!val_size.has_value() || *val_size != 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.
== 0
src/util/simplify_expr.cpp
Outdated
{ | ||
result_expr.make_nil(); | ||
break; | ||
} | ||
|
||
// can we determine the current offset, and is it a byte-sized |
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.
Comment belongs above, since the "can we determine" and the byte alignment question are now checked seperately
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 think this is still wrong -- "Can we determine the current offset?" belongs above if(!m_offset.has_value() || ...)
, then "Is it a byte-sized member?" belongs here.
@kroening for the breakages that didn't cause a CI failure suggest adding a test case |
2621da2
to
fe9223e
Compare
m_offset>=offset_int+update_size) | ||
else if( | ||
update_size.has_value() && *update_size > 0 && | ||
*m_offset >= offset_int + *update_size) | ||
break; |
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.
consider putting braces around break
(preceding multi-line conditional) to improve readability
auto el_size = pointer_offset_bits(op_type.subtype(), ns); | ||
if( | ||
!el_size.has_value() || *el_size == 0 || (*el_size) % 8 != 0 || | ||
(*val_size) % 8 != 0) | ||
return true; |
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.
consider putting braces around return
(preceding multi-line conditional) to improve readability
if( | ||
sub_size.has_value() && *sub_size > 0 && | ||
!to_integer(index_expr.index(), i)) | ||
return (*o) + i * (*sub_size); |
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.
consider putting braces around return
(preceding multi-line conditional) to improve readability
throw "can't flatten byte_update for sub-type without size"; | ||
|
||
mp_integer sub_size = *sub_size_opt; |
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 &
throw "byte_update of unknown width:\n"+src.pretty(); | ||
|
||
mp_integer element_size = *element_size_opt; |
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 &
mp_integer alloc_size; | ||
|
||
if(elem_size<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.
I think there was some value in the != 0
check here as we are going to divide by elem_size
later on, but that might already be implied by an invariant of pointer_offset_size()
.
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.
fixed
fe9223e
to
3b89aa5
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.
One nitpick, otherwise lgtm.
src/util/simplify_expr.cpp
Outdated
{ | ||
result_expr.make_nil(); | ||
break; | ||
} | ||
|
||
// can we determine the current offset, and is it a byte-sized |
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 think this is still wrong -- "Can we determine the current offset?" belongs above if(!m_offset.has_value() || ...)
, then "Is it a byte-sized member?" belongs here.
3b89aa5
to
03aceea
Compare
Fixed the comment |
There is performance cost:
With -O2 or -O3 the difference is 1.50s vs. 1.24s |
53e10d9
to
f06e62e
Compare
f06e62e
to
5ff66cb
Compare
Rebased. |
5ff66cb
to
bd5e6d8
Compare
@kroening Could you please rebase again? With the continuous evaluation set-up prepared by @peterschrammel we should surely notice if this change truly results in a performance impact. |
bd5e6d8
to
3d811f0
Compare
Rebase done. |
28f0abe
to
efdc901
Compare
efdc901
to
4568839
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.
Passed Diffblue compatibility checks (cbmc commit: 4568839).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/85642915
4568839
to
3f59028
Compare
New data, on Linux: clang++ 3.5.0 -O2: clang++ 6.0.1 -O2: g++ 8.2.0 -O2: I.e., this delivers a performance improvement on Linux. Will merge once CIed. |
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.
Passed Diffblue compatibility checks (cbmc commit: 3f59028).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/86391538
This removes another case of using -1 as 'error value': pointer_offset_size and variants.