Skip to content

Print negative hex instead of -positive#981

Merged
danielsn merged 7 commits intomodel-checking:mainfrom
danielsn:fix_hex_output
Mar 30, 2022
Merged

Print negative hex instead of -positive#981
danielsn merged 7 commits intomodel-checking:mainfrom
danielsn:fix_hex_output

Conversation

@danielsn
Copy link
Contributor

@danielsn danielsn commented Mar 25, 2022

Description of changes:

CBMC requires hex constants to be in 2's complement format.
Currently we use {:X} format, which prints twos complement for primitive integers, but not for bignums.
Instead, make the 2s complement version ourselves.

Resolved issues:

Resolves #982

Call-outs:

Adding additional asserts revealed #996, which had been latent in the codebase

Testing:

  • How is this change tested?

    • Added an additional unit test.
    • Confirmed that this fixes @adpaco-aws's issue
  • Is this a refactor change? No

Checklist

  • Each commit message has a non-empty body, explaining why the change was made
  • Methods or procedures are documented
  • Regression or unit tests are included, or existing tests cover the modified code
  • My PR is restricted to a single feature or bugfix

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

@danielsn danielsn requested a review from a team as a code owner March 25, 2022 17:48
@danielsn danielsn marked this pull request as draft March 25, 2022 17:48
@tedinski
Copy link
Contributor

Since we definitely got this wrong already, can we make sure we have this factored out into a function with unit tests before we merge?

@danielsn danielsn force-pushed the fix_hex_output branch 2 times, most recently from 14aa187 to 5bb5a4f Compare March 28, 2022 19:11
@danielsn danielsn marked this pull request as ready for review March 28, 2022 19:12
Copy link
Contributor

@celinval celinval left a comment

Choose a reason for hiding this comment

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

Thanks for doing this. Can you please add a test case that was making CBMC do the wrong thing?

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can you break down this test into a few tests? At least one per category.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a test with #[should_panic]?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did, but then had to disable them because of #996

Copy link
Contributor

@celinval celinval left a comment

Choose a reason for hiding this comment

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

This looks good. Just one question.

Copy link
Contributor

@celinval celinval left a comment

Choose a reason for hiding this comment

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

Just a tiny comment.

/// An integer, encoded as a hex string
FreeformHexInteger(BigInt),
/// A constant, stored as a bit pattern (negative numbers in 2's complement).
FreeformBitpattern(BigUint),
Copy link
Contributor

Choose a reason for hiding this comment

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

Tiny little change. This should be Pascal case: FreeformBitPattern

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

@danielsn danielsn merged commit 768380a into model-checking:main Mar 30, 2022
@danielsn danielsn deleted the fix_hex_output branch March 30, 2022 22:50
@adpaco-aws adpaco-aws mentioned this pull request Apr 1, 2022
4 tasks
tedinski pushed a commit to tedinski/rmc that referenced this pull request Apr 26, 2022
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.

We should print 2's complement hex constants, not sign/magnitude

3 participants