Skip to content

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

Closed
@RalfJung

Description

@RalfJung
Member

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

RalfJung commented on Jan 31, 2023

@RalfJung
MemberAuthor

#106908 landed in that range, seems like the most likely culprit? Cc @cjgillot

self-assigned this
on Jan 31, 2023
matthiaskrgr

matthiaskrgr commented on Jan 31, 2023

@matthiaskrgr
Member

@RalfJung what does the -O flag do? I couldn't find it mentioned in the readme. :/

RalfJung

RalfJung commented on Jan 31, 2023

@RalfJung
MemberAuthor

That's the regular rustc -O, turning on optimizations. Miri inherits all rustc flags.

added 2 commits that reference this issue on Feb 2, 2023

Rollup merge of rust-lang#107524 - cjgillot:both-storage, r=RalfJung

4cf01cf

Rollup merge of rust-lang#107524 - cjgillot:both-storage, r=RalfJung

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

Metadata

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

    Participants

    @RalfJung@matthiaskrgr@cjgillot@bjorn3@Noratrieb

    Issue actions

      Bad MIR: StorageLive on a local that was already live with opt-level=4 · Issue #107511 · rust-lang/rust