generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 129
Add support for anonymous nested statics #3953
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
21e9454
codegen support for pointer to anon static
d689ea2
Add test for pointer to constant memory allocation
873a185
create wrapper around codegen_const_allocation for clarity
6ae6f9d
improve test: check that both aliases see mutations
1f0828b
refactor is_anon_static into function in reachability.rs
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
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,57 @@ | ||
| // Copyright Kani Contributors | ||
| // SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
|
||
| // Test that Kani can codegen statics that contain pointers to nested statics. | ||
| // See https://github.com/model-checking/kani/issues/3904 | ||
|
|
||
| mod example_1 { | ||
| // FOO contains a pointer to the anonymous nested static alloc2. | ||
| // The MIR is: | ||
| // alloc1 (static: FOO, size: 8, align: 8) { | ||
| // ╾───────alloc2────────╼ │ ╾──────╼ | ||
| // } | ||
|
|
||
| // alloc2 (static: FOO::{constant#0}, size: 4, align: 4) { | ||
| // 2a 00 00 00 │ *... | ||
| // } | ||
| static mut FOO: &mut u32 = &mut 42; | ||
|
|
||
| #[kani::proof] | ||
| fn main() { | ||
| unsafe { | ||
| *FOO = 43; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| mod example_2 { | ||
| // FOO and BAR both point to the anonymous nested static alloc2. | ||
| // The MIR is: | ||
| // alloc3 (static: BAR, size: 8, align: 8) { | ||
| // ╾───────alloc2────────╼ │ ╾──────╼ | ||
| // } | ||
|
|
||
| // alloc2 (static: FOO::{constant#0}, size: 4, align: 4) { | ||
| // 2a 00 00 00 │ *... | ||
| // } | ||
|
|
||
| // alloc1 (static: FOO, size: 8, align: 8) { | ||
| // ╾───────alloc2────────╼ │ ╾──────╼ | ||
| // } | ||
|
|
||
| static mut FOO: &mut i32 = &mut 12; | ||
| static mut BAR: *mut i32 = unsafe { FOO as *mut _ }; | ||
|
|
||
| #[kani::proof] | ||
| fn main() { | ||
| unsafe { | ||
| // check that we see the same initial value from all aliases | ||
| assert_eq!(*FOO, 12); | ||
| assert_eq!(*BAR, 12); | ||
| *FOO = 13; | ||
| // check that we see the same mutated value from all aliases | ||
| assert_eq!(*FOO, 13); | ||
| assert_eq!(*BAR, 13); | ||
| } | ||
| } | ||
| } |
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,25 @@ | ||
| // Copyright Kani Contributors | ||
| // SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
|
||
| // Test that Kani can codegen statics that contain pointers to constant (i.e., immutable) allocations. | ||
| // Test taken from https://github.com/rust-lang/rust/issues/79738#issuecomment-1946578159 | ||
|
|
||
| // The MIR is: | ||
| // alloc4 (static: BAR, size: 16, align: 8) { | ||
| // ╾─────alloc3<imm>─────╼ 01 00 00 00 00 00 00 00 │ ╾──────╼........ | ||
| // } | ||
|
|
||
| // alloc3 (size: 4, align: 4) { | ||
| // 2a 00 00 00 │ *... | ||
| // } | ||
|
|
||
| // alloc1 (static: FOO, size: 16, align: 8) { | ||
| // ╾─────alloc3<imm>─────╼ 01 00 00 00 00 00 00 00 │ ╾──────╼........ | ||
| // } | ||
| pub static FOO: &[i32] = &[42]; | ||
| pub static BAR: &[i32] = &*FOO; | ||
|
|
||
| #[kani::proof] | ||
| fn main() { | ||
| assert_eq!(FOO.as_ptr(), BAR.as_ptr()); | ||
| } |
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.