add tests for fn pointers

This commit is contained in:
Oliver Schneider 2016-06-13 12:29:01 +02:00
parent 4d090fa693
commit 9565d48203
No known key found for this signature in database
GPG key ID: 56D6EEA0FC67AC46
2 changed files with 27 additions and 0 deletions

View file

@ -0,0 +1,13 @@
#![feature(custom_attribute)]
#![allow(dead_code, unused_attributes)]
fn f() {}
#[miri_run]
fn deref_fn_ptr() -> i32 {
unsafe {
*std::mem::transmute::<fn(), *const i32>(f) //~ ERROR: tried to dereference a function pointer
}
}
fn main() {}

View file

@ -0,0 +1,14 @@
#![feature(custom_attribute, box_syntax)]
#![allow(dead_code, unused_attributes)]
#[miri_run]
fn deref_fn_ptr() {
//FIXME: this span is wrong
let x = box 42; //~ ERROR: tried to treat a memory pointer as a function pointer
unsafe {
let f = std::mem::transmute::<Box<i32>, fn()>(x);
f()
}
}
fn main() {}