Skip to content

Invariant cleanup in flattening/boolbv_index #3044

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

hannes-steffenhagen-diffblue
Copy link
Contributor

@hannes-steffenhagen-diffblue hannes-steffenhagen-diffblue commented Sep 25, 2018

  • Each commit message has a non-empty body, explaining why the change was made.
  • My contribution is formatted in line with CODING_STANDARD.md.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • 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).
  • My commit message includes data points confirming performance improvements (if claimed) (not applicable).
  • My PR is restricted to a single feature or bugfix.
  • 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: c91b88b).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/85891642


if(array_size*width!=array_bv.size())
throw "unexpected array size";
DATA_INVARIANT(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Make that a second argument to convert_bv?

Copy link
Contributor

@NlightNFotis NlightNFotis left a comment

Choose a reason for hiding this comment

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

Reasonable. Just one question.

@@ -256,7 +256,7 @@ bvt boolbvt::convert_index(const index_exprt &expr)

typet constant_type=index.type(); // type of index operand

assert(array_size>0);
Copy link
Contributor

Choose a reason for hiding this comment

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

My only request is perhaps a better error message here? This shows what's going on, but not why. But I'm not too fussed about it to be honest.

@hannes-steffenhagen-diffblue hannes-steffenhagen-diffblue force-pushed the feature-invariant_cleanup-flattening-index branch from c91b88b to be2046d Compare September 26, 2018 14:31
@hannes-steffenhagen-diffblue
Copy link
Contributor Author

@NlightNFotis @tautschnig I believe I've addresses your comments, can you re-review once CI passes?

@@ -62,7 +62,7 @@ bvt boolbvt::convert_index(const index_exprt &expr)

// Must have a finite size
mp_integer array_size = numeric_cast_v<mp_integer>(array_type.size());

PRECONDITION(array_size.is_ulong());
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd not use this. See below.


if(array_size*width!=array_bv.size())
throw "unexpected array size";
const bvt &array_bv = convert_bv(array, array_size.to_ulong() * width);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use numeric_cast_v<std::size_t>(array_size * width) as it will 1) make sure there is no risk for overflow in the multiplication, 2) combine the check and the conversion, and 3) hide the implementation detail that bigint/.to_ulong is.

assert(array_size>0);
DATA_INVARIANT(
array_size > 0,
"non-positive array sizes are forbidden by the C standard");
Copy link
Collaborator

Choose a reason for hiding this comment

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

This isn't about C code anymore, so we should talk about goto programs, not C code.

Copy link
Contributor

Choose a reason for hiding this comment

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

We wrote this error message because we thought that goto-programs essentially model C semantics. It seems our assumption is wrong.

Copy link
Contributor

Choose a reason for hiding this comment

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

Will it be okay to change it to something like "non-positive array sizes are not allowed in goto-programs"? The only problem is that I also feel kind of uneasy not being able to point to a formal standard regarding semantics like that, no matter how self-evident or obvious it might seem. Thoughts @tautschnig ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Historically goto-programs and C semantics have been very close, but we are trying to get this disentangled (after all a considerable business is coming from the Java front-end :-) ). I understand your sentiment, and one day we'll hopefully get goto-program semantics documented. Please use the updated message that you suggested.

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

@hannes-steffenhagen-diffblue hannes-steffenhagen-diffblue force-pushed the feature-invariant_cleanup-flattening-index branch from be2046d to 1bc88a3 Compare September 26, 2018 16:51
Also use the expected_width parameter to move one check into convert_bv
@hannes-steffenhagen-diffblue hannes-steffenhagen-diffblue force-pushed the feature-invariant_cleanup-flattening-index branch from 1bc88a3 to 7baf62d Compare September 27, 2018 09:25
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: 7baf62d).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/86129076

@NlightNFotis
Copy link
Contributor

@tautschnig This has been fixed, and all CI checks now pass. Can you check if it's okay now, so that I can merge it if it is?

@tautschnig tautschnig merged commit da8d2ab into diffblue:develop Sep 27, 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.

4 participants