Skip to content

Simplifier: transform ((struct A)x).field1 into x.a.b.field2 #3562

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 Dec 11, 2018

This will take place if field1 and field2 have matching types and offsets within
struct A and the original struct type of 'x'. This is particularly important for the Java
frontend, where Java like "Map m = new HashMap(); return m.size()" will generate GOTO that
extracts the class-identifier from a Map*, but Map* and HashMap* are likely not structurally
equivalent (HashMap might have a superclass other than Object, or have fields above those
posessed by Map (which is an interface in fact, so has none)).

That means value_set_dereferencet leaves us with an expression like
((Map)dynamic_object1)[email protected].@class_identifier, which the simplifier can now
handle, enabling symex to determine the actual type is HashMap and so avoid exploring code
that is in truth unreachable.

@@ -0,0 +1,6 @@

Copy link
Member

Choose a reason for hiding this comment

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

spurious newline

^Passing problem to
^warning: ignoring
--
The "Passing problem to..." line is a sign that symex couldn't prove the
Copy link
Member

Choose a reason for hiding this comment

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

What about "remaining VCCs: 0" ?

Copy link
Member

Choose a reason for hiding this comment

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

Could you match the simplified expression on the --program-only output?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a test checking the expected expression is in the --show-vccs output

@smowton smowton force-pushed the smowton/feature/simplify-truncating-cast branch from bff338a to fd1bf5c Compare December 11, 2018 16:52
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.

🚫
This PR failed Diffblue compatibility checks (cbmc commit: bff338a).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/94378823
Status will be re-evaluated on next push.
Please contact @peterschrammel, @thk123, or @allredj for support.

Common spurious failures:

  • the cbmc commit has disappeared in the mean time (e.g. in a force-push)
  • the author is not in the list of contributors (e.g. first-time contributors).

The incompatibility may have been introduced by an earlier PR. In that case merging this
PR should be avoided unless it fixes the current incompatibility.

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: fd1bf5c).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/94384684

@@ -0,0 +1,11 @@
CORE
Test.class
--function Test.main --no-propagation --unwind 10 --show-vcc
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should be --no-simplify instead of --no-propagation, because it's really the former that you are changing here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@smowton smowton force-pushed the smowton/feature/simplify-truncating-cast branch from fd1bf5c to 105a87d Compare December 14, 2018 16:55
@peterschrammel
Copy link
Member

This will take place if field1 and field2 have matching types and offsets within
struct A and the original struct type of 'x'. This is particularly important for the Java
frontend, where Java like "Map m = new HashMap(); return m.size()" will generate GOTO that
extracts the class-identifier from a Map*, but Map* and HashMap* are likely not structurally
equivalent (HashMap might have a superclass other than Object, or have fields above those
posessed by Map (which is an interface in fact, so has none)).

That means value_set_dereferencet leaves us with an expression like
((Map)dynamic_object1)[email protected].@class_identifier, which the simplifier can now
handle, enabling symex to determine the actual type is HashMap and so avoid exploring code
that is in truth unreachable.
@smowton smowton force-pushed the smowton/feature/simplify-truncating-cast branch from 105a87d to d47a07c Compare December 17, 2018 13:30
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: d47a07c).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/94977771

@tautschnig tautschnig merged commit 1060c57 into diffblue:develop Dec 17, 2018
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.

6 participants