Skip to content

Simplify byte_extract(constant, o, t) when sizeof(t) < sizeof(constant) #3974

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
merged 1 commit into from
Jan 30, 2019

Conversation

tautschnig
Copy link
Collaborator

We previously restricted this case to sizeof(t) == sizeof(constant) to discard
some cases of flexible arrays. It wasn't actually a sound way of detecting that
case, and also disallowed many cases where we can safely simplify. Instead, look
at the type and detect (possible) flexible array members.

  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

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

{
int a[7] = {0};

//CBMC reports wrong results for 256, -2147221455, -2147221455, -2147221455, 16, -2147483600, 16384
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this still true, or was this the bug report that we're exhibiting we've fixed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed, too naive copying. I've updated the comment as well as the original file (main.c in the same directory).

// flexible array members at the end of a struct
if(bits.has_value() && mp_integer(bits->size()) == *el_size + *offset * 8)
// make sure we don't lose bits with flexible struct members
const bool has_flexible_struct_member = has_subtype(
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: these appear to be called flexible array members elsewhere, so we might call this struct_has_flexible_array_member

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, done!

@tautschnig tautschnig force-pushed the simplify-byte-extract-ext branch from 329decb to 07e8b00 Compare January 28, 2019 16:16
// flexible array members at the end of a struct
if(bits.has_value() && mp_integer(bits->size()) == *el_size + *offset * 8)
// make sure we don't lose bits with structs containing flexible array members
const bool struct_has_flexible_array_member = has_subtype(
Copy link
Member

Choose a reason for hiding this comment

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

⛏ Might be worth factoring that out into a utility to avoid someone recoding that at the next occasion...

Copy link
Collaborator Author

@tautschnig tautschnig Jan 29, 2019

Choose a reason for hiding this comment

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

I'll in this case not follow the advice for two reasons: 1) This is an over-approximating check, even struct_has_flexible_array_member == true need not mean that there genuinely are flexible array members (which is ok in this context, it just mean we don't simplify although we possibly could); 2) I haven't found any other bits of the code outside the C type checker that currently try to deal with this special case. Should a need for that arise, of course, we should refactor. I hope that's ok!

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

We previously restricted this case to sizeof(t) == sizeof(constant) to discard
some cases of flexible arrays. It wasn't actually a sound way of detecting that
case, and also disallowed many cases where we can safely simplify. Instead, look
at the type and detect (possible) flexible array members.
@tautschnig tautschnig force-pushed the simplify-byte-extract-ext branch from 407992e to 919d265 Compare January 29, 2019 18:14
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: 919d265).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/99078961

@tautschnig tautschnig merged commit 1c7926f into diffblue:develop Jan 30, 2019
@tautschnig tautschnig deleted the simplify-byte-extract-ext branch January 30, 2019 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants