Skip to content
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

Custom MIR: bad span for assignments #113549

Open
RalfJung opened this issue Jul 10, 2023 · 1 comment
Open

Custom MIR: bad span for assignments #113549

RalfJung opened this issue Jul 10, 2023 · 1 comment
Labels
A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@RalfJung
Copy link
Member

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

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 10, 2023
@saethlin saethlin added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jul 10, 2023
@JakobDegen
Copy link
Contributor

So if you change this to

#![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: i32;
        {
            _observe = x;
            Return()
        }

    }
}

It does the right thing. The reason for this is that the let statement results in the assignment being taken apart and put back together in the mir! macro, which loses the span info. This can possibly be fixed with some cleverness, not sure

bors added a commit to rust-lang/miri that referenced this issue Jul 14, 2023
RalfJung pushed a commit to RalfJung/rust that referenced this issue Jul 14, 2023
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 T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants