Skip to content
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

Enable test for bitreverse intrinsic #926

Merged
merged 5 commits into from
Mar 15, 2022

Conversation

adpaco-aws
Copy link
Contributor

Description of changes:

Enables the "fixme" test we prepared for bitreverse after some modifications (use nondeterministic index, remove tests for signed integer types).

Resolved issues:

Resolves #778

Testing:

  • How is this change tested? Existing regression + this new test.

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

@adpaco-aws adpaco-aws requested a review from a team as a code owner March 14, 2022 17:03
Comment on lines +17 to +19
let n: usize = kani::any();
kani::assume(n < len);
assert!($get_bit_name(a, n) == $get_bit_name(b, (len - 1) - n));
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

Comment on lines -7 to -9
// Note: Support for `__builtin_bitreverse` in CBMC is being added in
// https://github.com/diffblue/cbmc/pull/6581
// Tracking issue: https://github.com/model-checking/kani/issues/778
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this might not belong in this test case if there's nothing to change here, but this work remains to be done, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure what you mean, we are enabling this test because support for __builtin_bitreverse is now available in CBMC. The Kani issue will be resolved by this PR, note that most of the work on Kani's end was added in #779

Copy link
Contributor

Choose a reason for hiding this comment

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

we are enabling this test because support for __builtin_bitreverse is now available in CBMC.

Ah, that's what I was missing. ok.

Comment on lines +35 to +39
// `reverse_bits` is also defined for signed integer types by casting the
// number into the corresponding unsigned type and then casting the result
// into the original signed type. This causes overflows unless we restrict
// their values considerably, making the signed versions not very
// interesting to test here.
Copy link
Contributor

Choose a reason for hiding this comment

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

If bit reverse works on signed types in rust... shouldn't we test that we translate it correctly still?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, the translation is the same. Just to be clear, this is how it is defined: https://github.com/rust-lang/rust/blob/master/library/core/src/num/int_macros.rs#L277-L279

Would you be happy if we add a test like this for each integer type?

assert!((0 as i8).reverse_bits() == 0);

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, but a test is meant to defend us against changes in the implementation, and there's certainly room for confusing bugs to show up here when converting between signed/unsigned.

Plus... it's not clear to me we should be issuing overflows on this operation on a signed integer. Those cases failing might actually be indicating unwanted behavior from our translation here.

BUT, this does seem like a huge corner case, people probably just don't reverse bits on signed integers much. I'll approve but maybe we should have an issue open about what reversing on signed integers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree - I was quite shocked when I realized there were signed versions. I am going to merge this as it is and look forward to a discussion on #934 since we are already skipping testing for signed versions in other cases (#880 and #883).

@tedinski
Copy link
Contributor

I think is was ready, and the test taking a long time is bugging me, so merging!

@tedinski tedinski merged commit e6fb988 into model-checking:main Mar 15, 2022
@adpaco-aws adpaco-aws mentioned this pull request Mar 17, 2022
tedinski pushed a commit to tedinski/rmc that referenced this pull request Apr 22, 2022
tedinski pushed a commit to tedinski/rmc that referenced this pull request Apr 25, 2022
tedinski pushed a commit to tedinski/rmc that referenced this pull request Apr 26, 2022
tedinski pushed a commit that referenced this pull request Apr 27, 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.

Ensure testing for bitreverse when support in CBMC is available
2 participants