Skip to content

Use appropriate numeric_cast_v<T> instead of deprecated integer2unsigned #3047

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
Oct 15, 2018

Conversation

tautschnig
Copy link
Collaborator

@tautschnig tautschnig commented Sep 26, 2018

This includes several type fixes - only three instances ended up as
numeric_cast_v, all others uses of integer2unsigned were actually in
contexts where some other type was required.

  • Each commit message has a non-empty body, explaining why the change was made.
  • My contribution is formatted in line with CODING_STANDARD.md.
  • [n/a] 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).
  • [n/a] My commit message includes data points confirming performance improvements (if claimed).
  • 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.

This PR failed Diffblue compatibility checks (cbmc commit: f8e589f).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/85989246
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).

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

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

@@ -549,10 +549,12 @@ exprt flatten_byte_update(
// zero-extend the value, but only if needed
exprt value_extended;

if(width>integer2unsigned(element_size)*8)
if(width > element_size * 8)
Copy link
Member

Choose a reason for hiding this comment

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

This looks inconsistent: width is a size_t (which is parsed with integer2size_t above). element_size is an mp_integer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thus everything will be converted to mp_integer, which avoids falling for an (unsigned) integer overflow.

unsigned unsigned_value=integer2unsigned(int_value);
value+=static_cast<char>(unsigned_value);

value += numeric_cast_v<char>(op);
}
Copy link
Member

Choose a reason for hiding this comment

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

I am a bit worried about this one -- the previous implementation would have done the conversion, say from -1 to 255; now you get an invariant failure.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do negative numbers make sense in this context? I'm happy to amend this in any reasonable way. The code does not seem to be used anywhere, so I wouldn't know how to test, I'm afraid.

Copy link
Member

Choose a reason for hiding this comment

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

#3168 takes care of this!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, I will rebase once that is merged.

This includes several type fixes - only three instances ended up as
numeric_cast_v<unsigned>, all others uses of integer2unsigned were actually in
contexts where some other type was required.
@tautschnig
Copy link
Collaborator Author

@kroening This is now rebased on top of (the merged) #3168 (string_constantt cleanup).

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

@kroening kroening merged commit 7bf48c0 into diffblue:develop Oct 15, 2018
@tautschnig tautschnig deleted the integer2unsigned branch October 15, 2018 08:26
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.

7 participants