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

Fix std overrides in crates where std is used as a feature #2194

Merged
merged 4 commits into from
Feb 8, 2023

Conversation

zhassan-aws
Copy link
Contributor

Description of changes:

Kani's std overrides relied on creating an alias for core::assert up front to use for error checking in various macros (assert, panic, etc.). Creating the alias upfront doesn't work properly in crates with no_std where std is used as a feature (see #2187). This PR updates the std overrides to use core::assert directly when an std feature is enabled.

Resolved issues:

Resolves #2187

Related RFC:

Optional #ISSUE-NUMBER.

Call-outs:

To avoid code duplication, I tried creating a macro that calls __kani__workaround_core_assert under not(std) and core::assert otherwise. However, I ran into the same error reported in #2187.

Testing:

  • How is this change tested? Added one 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.

@zhassan-aws zhassan-aws requested a review from a team as a code owner February 7, 2023 07:45
fn foo() {
let x: i32 = kani::any();
let y = 0;
std::debug_assert!(x + y == x, "Message");
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also have a test where the assertion fails?

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 don't think this is necessary, since we're mainly checking that compilation goes through. There are many other tests that check for failing assertions.

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.

I'm worried that this is getting out of control. We should investigate a more robust solution.

Thanks for the quick fix though.

@zhassan-aws zhassan-aws merged commit 832bc67 into model-checking:main Feb 8, 2023
@zhassan-aws zhassan-aws deleted the iss2187 branch February 8, 2023 02:18
zhassan-aws added a commit to zhassan-aws/kani that referenced this pull request Mar 7, 2023
@zhassan-aws zhassan-aws mentioned this pull request Mar 7, 2023
4 tasks
zhassan-aws added a commit that referenced this pull request Mar 7, 2023
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.

Issue finding debug_assert in no_std crates when std enabled
3 participants