-
Notifications
You must be signed in to change notification settings - Fork 160
Fix loop-contract transform for post-#145513 deref temporaries #4659
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
tautschnig
merged 4 commits into
model-checking:main
from
tautschnig:fix-loop-contract-deref-temps
Jul 23, 2026
+89
−8
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f5fda45
Fix loop-contract transform for post-#145513 deref temporaries
tautschnig 01d4116
Add check-name header to second expected block
tautschnig 6daeac7
Merge branch 'main' into fix-loop-contract-deref-temps
tautschnig 0e0e5c6
Merge branch 'main' into fix-loop-contract-deref-temps
tautschnig File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| lookup.loop_invariant_base.1\ | ||
| - Status: SUCCESS\ | ||
| - Description: "Check invariant before entry for loop lookup.0" | ||
|
|
||
| - Status: SUCCESS\ | ||
| - Description: "assertion failed: n <= 2" | ||
|
|
||
| VERIFICATION:- SUCCESSFUL | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // Copyright Kani Contributors | ||
| // SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
|
||
| // kani-flags: -Z loop-contracts | ||
|
|
||
| //! Check for-loop invariant for a loop whose pattern destructures the | ||
| //! iterator element through a reference, e.g. `for (i, &p) in ...`. | ||
| //! Such patterns introduce compiler-generated deref temporaries in the | ||
| //! pattern-binding block. Those temporaries used to be assigned via | ||
| //! `Rvalue::CopyForDeref`, which rust-lang/rust#145513 turned into plain | ||
| //! copies, and the loop-contract transformation has to keep their | ||
| //! assignments in place instead of treating them like pattern bindings | ||
| //! (see https://github.com/model-checking/kani/issues/4658). | ||
| //! This is a regression test for the spurious "dereference failure" | ||
| //! checks Kani used to emit for this pattern; it is modelled after | ||
| //! `number_of_digits_decimal_left_shift` in the Rust standard library. | ||
|
|
||
| #![feature(proc_macro_hygiene)] | ||
| #![feature(stmt_expr_attributes)] | ||
|
|
||
| const TABLE: [u8; 16] = [5, 2, 5, 1, 2, 5, 6, 2, 5, 3, 1, 2, 5, 1, 5, 6]; | ||
|
|
||
| fn lookup(digits: &[u8; 16], num_digits: usize, a: usize, b: usize) -> usize { | ||
| let num_new_digits: usize = 2; | ||
| let pow5 = &TABLE[a..]; | ||
|
|
||
| #[kani::loop_invariant(num_new_digits > 1)] | ||
| for (i, &p5) in pow5.iter().enumerate().take(b - a) { | ||
| if i >= num_digits { | ||
| return num_new_digits - 1; | ||
| } else if digits[i] == p5 { | ||
| continue; | ||
| } else if digits[i] < p5 { | ||
| return num_new_digits - 1; | ||
| } else { | ||
| return num_new_digits; | ||
| } | ||
| } | ||
| num_new_digits | ||
| } | ||
|
|
||
| #[kani::proof] | ||
| fn check_ref_pattern_deref_temp() { | ||
| let digits: [u8; 16] = kani::any(); | ||
| let num_digits: usize = kani::any_where(|x| *x <= 16); | ||
| let a: usize = kani::any_where(|x| *x < 8); | ||
| let b: usize = kani::any_where(|x| *x >= a && *x <= 16); | ||
| let n = lookup(&digits, num_digits, a, b); | ||
| assert!(n <= 2); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.