Closed
Description
Consider this code:
fn main() {
let mut sum = 0;
let a = [0, 10, 20, 30];
for i in 0..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
This is a fairly recent regression (ad48c10 was good, a322848 is bad; commit range: ad48c10...a322848).
Cc @rust-lang/wg-mir-opt
Activity
RalfJung commentedon Jan 31, 2023
#106908 landed in that range, seems like the most likely culprit? Cc @cjgillot
matthiaskrgr commentedon Jan 31, 2023
@RalfJung what does the
-O
flag do? I couldn't find it mentioned in the readme. :/RalfJung commentedon Jan 31, 2023
That's the regular
rustc -O
, turning on optimizations. Miri inherits all rustc flags.Rollup merge of rust-lang#107524 - cjgillot:both-storage, r=RalfJung
Rollup merge of rust-lang#107524 - cjgillot:both-storage, r=RalfJung