rust-lang / miri

An interpreter for Rust's mid-level intermediate representation
Apache License 2.0
4.44k stars 340 forks source link

internal compiler error on atomic_xchg::<Trait>() #182

Closed dwrensha closed 7 years ago

dwrensha commented 7 years ago

Consider the following program:

// test.rs

#![feature(core_intrinsics)]

pub trait Foo {}

pub struct Bar;

impl Foo for Bar {}

pub fn main() {
    let b = Box::new(Bar) as Box<Foo>;
    let mut x: *const Foo = &*b;
    let y: *const Foo = &*b;
    unsafe {
        ::std::intrinsics::atomic_xchg(&mut x, y);
    }
}

When I try to compile test.rs with rustc, I get a monomorphization error:

$ rustc test.rs
error[E0511]: invalid monomorphization of `atomic_xchg` intrinsic: expected basic integer type, found `*const Foo`
  --> test.rs:16:9
   |
16 |         ::std::intrinsics::atomic_xchg(&mut x, y);
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error(s)

When I run test.rs with miri, I expect to see a similar error. Instead, I get an "internal compiler error":

$ cargo run --bin miri -- test.rs 
    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
     Running `target/debug/miri test.rs`
error: internal compiler error: src/eval_context.rs:1143: value_to_primval can't work with fat pointers

thread 'main' panicked at 'Box<Any>', /checkout/src/librustc_errors/lib.rs:480
dwrensha commented 7 years ago

Similar to #181. If the rustc typechecker caught these errors then there would be no problem.

oli-obk commented 7 years ago

I'd consider this a dupe. Let's keep it all in the other issue.