Skip to content

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

Conversation

smowton
Copy link
Contributor

@smowton smowton commented Feb 13, 2019

Otherwise this produces odd expressions like (1 + (int)2), which can lead to missed opportunities since that doesn't pass is_constant()

These can fool later simplifications by appearing to be non-constant.
Leaving this with trivially simplifiable expressions such as (0 + 0) means subsequent simplifications that
check for offset.is_constant() may be wrongly skipped.
@@ -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);
Copy link
Collaborator

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

Copy link
Contributor Author

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.

This test indirectly uses object_descriptor_exprt, which uses simplify_sum, which in turn requires
integer constants to have defined widths.
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.

✔️
Passed Diffblue compatibility checks (cbmc commit: 8c231e9).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/100903764

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.

✔️
Passed Diffblue compatibility checks (cbmc commit: 7d0ce45).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/100908538

@smowton smowton merged commit 0310a02 into diffblue:develop Feb 14, 2019
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