Skip to content

API change: from_integer for negative naturals #3016

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
Sep 21, 2018

Conversation

kroening
Copy link
Member

@kroening kroening commented Sep 21, 2018

This changes behavior for the case that from_integer is asked to produce a
natural number that is negative. Previously, a malformed constant_exprt
with nil id was returned; now a precondition fails.

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

@tautschnig tautschnig left a comment

Choose a reason for hiding this comment

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

I think this is good, except the use of PRECONDITION feels a bit weird and I'd thus suggest changes as below.

}
else if(type_id==ID_pointer)
{
if(int_value==0)
return null_pointer_exprt(to_pointer_type(type));
else
PRECONDITION(false);
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 written as

PRECONDITION(int_value == 0);
return null_pointer_exprt(to_pointer_type(type));

Copy link
Member Author

Choose a reason for hiding this comment

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

ok

@@ -158,11 +152,15 @@ constant_exprt from_integer(
return false_exprt();
else if(int_value==1)
return true_exprt();
else
PRECONDITION(false);
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 do:

PRECONDITION(int_value == 0 || int_value == 1);
if(int_value == 0)
  return false_exprt();
else
  return true_exprt();

Copy link
Member Author

Choose a reason for hiding this comment

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

ok

This changes behavior for the case that from_integer is asked to produce a
natural number that is negative.  Previously, a malformed constant_exprt
with nil id was returned; now a precondition fails.
@kroening kroening force-pushed the from_integer_negative_natural branch from a53b7a5 to 92eab68 Compare September 21, 2018 18:21
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: a53b7a5).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/85596705
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: 92eab68).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/85599486

@kroening kroening merged commit 13e3a3d into develop Sep 21, 2018
@kroening kroening deleted the from_integer_negative_natural branch September 21, 2018 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants