Skip to content

[MIR] bounds-checked indexing creates broken MIR #31482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
arielb1 opened this issue Feb 8, 2016 · 2 comments
Closed

[MIR] bounds-checked indexing creates broken MIR #31482

arielb1 opened this issue Feb 8, 2016 · 2 comments
Labels
A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html

Comments

@arielb1
Copy link
Contributor

arielb1 commented Feb 8, 2016

The first fruit of my MIR type-checking work:

pub fn cbk(x: usize) -> usize {
    [0][x]
}

Generated MIR:

fn(arg0: usize) -> usize {
    let var0: usize; // x
    let mut tmp0: usize;
    let mut tmp1: [usize; 1];
    let mut tmp2: ();
    let mut tmp3: usize;
    let mut tmp4: usize;
    let mut tmp5: bool;
    let mut tmp6: (&'static str, u32);
    let mut tmp7: &(&'static str, u32);

    bb0: {
        var0 = arg0;
        tmp1 = [const 0];
        tmp3 = var0;
        tmp4 = Len(tmp1);
        tmp5 = Lt(tmp3, tmp4);
        if(tmp5) -> [true: bb2, false: bb3];
    }

    bb1: {
        return;
    }

    bb2: {
        tmp0 = tmp1[tmp3];
        return = tmp0;
        goto -> bb1;
    }

    bb3: {
        tmp6 = (const "panic.rs", const 7);
        tmp7 = &mut tmp6; //~ ERROR &mut and late-bound region!
        core::panicking::panic_bounds_check(tmp7, tmp3, tmp4);
    }
}
@arielb1 arielb1 added the A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html label Feb 8, 2016
@nagisa
Copy link
Member

nagisa commented Feb 8, 2016

The tmp6 is supposed to become a constant (promoted rvalue) once we have a capability to make these happen. This justifies the ReStatic region.

@arielb1
Copy link
Contributor Author

arielb1 commented Feb 8, 2016

I guess. We just have to get rvalue promotion (or whatever) done before MIR borrowck.

@bors bors closed this as completed in b7cbbc3 Feb 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html
Projects
None yet
Development

No branches or pull requests

2 participants