You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fnmain(){letmut sum = 0;let a = [0,10,20,30];for i in0..a.len(){
sum += a[i];}println!("{sum}");}
When running this in Miri with -Zmir-opt-level=4 -O, we get an error:
error: Undefined Behavior: StorageLive on a local that was already live
--> tests/pass/loops.rs:4:9
|
4 | for i in 0..a.len() {
| ^ StorageLive on a local that was already live
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: BACKTRACE:
= note: inside `main` at tests/pass/loops.rs:4:9: 4:10
Remove both StorageLive and StorageDead in CopyProp.
Fixesrust-lang#107511rust-lang#106908 removed StorageDead without the accompanying StorageLive. In loops, execution would see repeated StorageLive, without any StorageDead, which is UB.
So when removing storage statements, we have to remove both StorageLive and StorageDead.
~I also added a MIR validation pass for StorageLive. It may be a bit overzealous.~
Consider this code:
When running this in Miri with
-Zmir-opt-level=4 -O
, we get an error:This is a fairly recent regression (ad48c10 was good, a322848 is bad; commit range: ad48c10...a322848).
Cc @rust-lang/wg-mir-opt
The text was updated successfully, but these errors were encountered: