-
Notifications
You must be signed in to change notification settings - Fork 273
Simplify and avoid redundant typecasts in build_object_descriptor #4183
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
smowton
merged 4 commits into
diffblue:develop
from
smowton:smowton/cleanup/simplify-object-descriptor
Feb 14, 2019
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2d72002
build_object_descriptor: avoid redundant typecasts
smowton 992a3c3
Simplify object descriptor offset after construction
smowton 8c231e9
Generics unit test: set integer widths
smowton 7d0ce45
Remove now-unnecessary simplify after object_descriptor_exprt::build
smowton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ Author: Daniel Kroening, [email protected] | |
#include "expr_util.h" | ||
#include "mathematical_types.h" | ||
#include "pointer_offset_size.h" | ||
#include "simplify_expr.h" | ||
|
||
bool constant_exprt::value_is_zero_string() const | ||
{ | ||
|
@@ -72,10 +73,11 @@ static void build_object_descriptor_rec( | |
exprt sub_size=size_of_expr(expr.type(), ns); | ||
CHECK_RETURN(sub_size.is_not_nil()); | ||
|
||
dest.offset()= | ||
plus_exprt(dest.offset(), | ||
mult_exprt(typecast_exprt(index.index(), index_type()), | ||
typecast_exprt(sub_size, index_type()))); | ||
dest.offset() = plus_exprt( | ||
dest.offset(), | ||
mult_exprt( | ||
typecast_exprt::conditional_cast(index.index(), index_type()), | ||
typecast_exprt::conditional_cast(sub_size, index_type()))); | ||
} | ||
else if(expr.id()==ID_member) | ||
{ | ||
|
@@ -87,9 +89,8 @@ static void build_object_descriptor_rec( | |
exprt offset=member_offset_expr(member, ns); | ||
CHECK_RETURN(offset.is_not_nil()); | ||
|
||
dest.offset()= | ||
plus_exprt(dest.offset(), | ||
typecast_exprt(offset, index_type())); | ||
dest.offset() = plus_exprt( | ||
dest.offset(), typecast_exprt::conditional_cast(offset, index_type())); | ||
} | ||
else if(expr.id()==ID_byte_extract_little_endian || | ||
expr.id()==ID_byte_extract_big_endian) | ||
|
@@ -100,10 +101,10 @@ static void build_object_descriptor_rec( | |
|
||
build_object_descriptor_rec(ns, be.op(), dest); | ||
|
||
dest.offset()= | ||
plus_exprt(dest.offset(), | ||
typecast_exprt(to_byte_extract_expr(expr).offset(), | ||
index_type())); | ||
dest.offset() = plus_exprt( | ||
dest.offset(), | ||
typecast_exprt::conditional_cast( | ||
to_byte_extract_expr(expr).offset(), index_type())); | ||
} | ||
else if(expr.id()==ID_typecast) | ||
{ | ||
|
@@ -145,6 +146,7 @@ void object_descriptor_exprt::build( | |
offset()=from_integer(0, index_type()); | ||
|
||
build_object_descriptor_rec(ns, expr, *this); | ||
simplify(offset(), ns); | ||
} | ||
|
||
shift_exprt::shift_exprt( | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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'm a bit worried about the cost, can you check that callees don't currently run this after invoking build? (And if they do, remove it from those places.)
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.
Checked, there was one redundant simplify (presumably working around the same issue). A couple of others use the offset to build a composite expression then simplify that, and so would have coincidentally dodged this problem. Some others uses
ode.offset().is_zero()
, which will probably have failed spuriously before when the offset was composite-but-constant.