forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#108175 - cjgillot:validate-storage, r=tmiasko
MIR-Validate StorageLive. `StorageLive` statements on a local which already has storage is banned by miri. This check is easy enough, and can detect bugs in MIR opts.
- Loading branch information
Showing
3 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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,30 @@ | ||
// compile-flags: -Zvalidate-mir -Ztreat-err-as-bug | ||
// failure-status: 101 | ||
// error-pattern: broken MIR in | ||
// error-pattern: StorageLive(_1) which already has storage here | ||
// normalize-stderr-test "note: .*\n\n" -> "" | ||
// normalize-stderr-test "thread 'rustc' panicked.*\n" -> "" | ||
// normalize-stderr-test "storage_live\[....\]" -> "storage_live[HASH]" | ||
// rustc-env:RUST_BACKTRACE=0 | ||
|
||
#![feature(custom_mir, core_intrinsics)] | ||
|
||
extern crate core; | ||
use core::intrinsics::mir::*; | ||
use core::ptr::{addr_of, addr_of_mut}; | ||
|
||
#[custom_mir(dialect = "built")] | ||
fn multiple_storage() { | ||
mir!( | ||
let a: usize; | ||
{ | ||
StorageLive(a); | ||
StorageLive(a); | ||
Return() | ||
} | ||
) | ||
} | ||
|
||
fn main() { | ||
multiple_storage() | ||
} |
This file contains 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,13 @@ | ||
error: internal compiler error: broken MIR in Item(WithOptConstParam { did: DefId(0:8 ~ storage_live[HASH]::multiple_storage), const_param_did: None }) (before pass CheckPackedRef) at bb0[1]: | ||
StorageLive(_1) which already has storage here | ||
--> $DIR/storage-live.rs:22:13 | ||
| | ||
LL | StorageLive(a); | ||
| ^^^^^^^^^^^^^^ | ||
|
||
error: the compiler unexpectedly panicked. this is a bug. | ||
|
||
query stack during panic: | ||
#0 [mir_const] preparing `multiple_storage` for borrow checking | ||
#1 [mir_promoted] processing MIR for `multiple_storage` | ||
end of query stack |