generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 131
Ensuring that MIR constants are marked as static consts #4233
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ebd3cd0
Ensuring that MIR constants are marked as static consts
3d69db9
Merge branch 'model-checking:main' into const_block
vonaka 6e52ccf
Fix tests
90be338
Bring modify_slice_elem test back
94c1504
Add further tests from issue 3905
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
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,11 @@ | ||
| assertion\ | ||
| - Status: SUCCESS\ | ||
| - Description: "|result| *result == Enum::Second"\ | ||
|
|
||
| assertion\ | ||
| - Status: SUCCESS\ | ||
| - Description: "|result| *result == Enum::First"\ | ||
|
|
||
| VERIFICATION:- SUCCESSFUL | ||
|
|
||
| Complete - 5 successfully verified harnesses, 0 failures, 5 total. |
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,74 @@ | ||
| // Copyright Kani Contributors | ||
| // SPDX-License-Identifier: Apache-2.0 OR MIT | ||
| // kani-flags: -Z function-contracts | ||
|
|
||
| //! Checking that constant blocks are correctly verified in contracts. | ||
| //! See https://github.com/model-checking/kani/issues/3905 | ||
|
|
||
| #![feature(ptr_alignment_type)] | ||
|
|
||
| use std::mem; | ||
| use std::ptr::{Alignment, NonNull}; | ||
|
|
||
| #[derive(PartialEq)] | ||
| enum Enum { | ||
| First, | ||
| Second, | ||
| } | ||
|
|
||
| #[kani::ensures(|result| *result == Enum::First)] | ||
| const fn first() -> Enum { | ||
| const { Enum::First } | ||
| } | ||
|
|
||
| #[kani::ensures(|result| *result == Enum::Second)] | ||
| const fn second() -> Enum { | ||
| Enum::Second | ||
| } | ||
|
|
||
| #[kani::proof_for_contract(first)] | ||
| pub fn check_first() { | ||
| let _ = first(); | ||
| } | ||
|
|
||
| #[kani::proof_for_contract(second)] | ||
| pub fn check_second() { | ||
| let _ = second(); | ||
| } | ||
|
|
||
| #[kani::ensures(|result| result.as_usize().is_power_of_two())] | ||
| pub const fn Align_of<T>() -> Alignment { | ||
| // This can't actually panic since type alignment is always a power of two. | ||
| const { Alignment::new(mem::align_of::<T>()).unwrap() } | ||
| } | ||
|
|
||
| #[kani::ensures(|result| result.as_usize().is_power_of_two())] | ||
| pub const fn Align_of_no_const<T>() -> Alignment { | ||
| // This can't actually panic since type alignment is always a power of two. | ||
| Alignment::new(mem::align_of::<T>()).unwrap() | ||
| } | ||
|
|
||
| #[kani::proof_for_contract(Align_of)] | ||
| pub fn check_of_i32() { | ||
| let _ = Align_of::<i32>(); | ||
| } | ||
|
|
||
| #[kani::proof_for_contract(Align_of_no_const)] | ||
| pub fn check_of_i32_no_const() { | ||
| let _ = Align_of_no_const::<i32>(); | ||
| } | ||
|
|
||
| #[kani::requires(true)] | ||
| pub const unsafe fn byte_add_n<T>(s: NonNull<T>, count: usize) -> NonNull<T> { | ||
| unsafe { NonNull::new_unchecked(s.as_ptr().byte_add(count)) } | ||
| } | ||
|
|
||
| #[kani::proof_for_contract(byte_add_n)] | ||
| pub fn non_null_byte_add_dangling_proof() { | ||
| let ptr = NonNull::<i32>::dangling(); | ||
| assert!(ptr.as_ptr().addr() == 4); | ||
| assert!(ptr.as_ptr().addr() <= (isize::MAX as usize)); | ||
| unsafe { | ||
| let _ = byte_add_n(ptr, 0); | ||
| } | ||
| } |
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
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.