Skip to content

Bad MIR: StorageLive on a local that was already live with opt-level=4 #107511

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

A-mir-optArea: MIR optimizationsC-bugCategory: This is a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions