Skip to content

Custom MIR: bad span for assignments #113549

Open
@RalfJung

Description

@RalfJung

Consider this code:

#![feature(custom_mir, core_intrinsics)]
use std::intrinsics::mir::*;

pub struct S(i32);

#[custom_mir(dialect = "runtime", phase = "optimized")]
fn main() {
    mir! {
        let x: i32;
        {
            let _observe = x;
            Return()
        }

    }
}

When running it in Miri, I wold expect this to point at the assignment. Instead it points at the entire mir! block:

error: Undefined Behavior: constructing invalid value: encountered uninitialized memory, but expected an integer
  --> src/main.rs:8:5
   |
8  | /     mir! {
9  | |         let x: i32;
10 | |         {
11 | |             let _observe = x;
...  |
14 | |
15 | |     }
   | |_____^ constructing invalid value: encountered uninitialized memory, but expected an integer

I've seen it use proper spans for Call terminators inside mir! blocks so I hope this is just an oversight and easy to fix. :)

Cc @JakobDegen

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions