Skip to content

Commit 60c7509

Browse files
committed
Auto merge of #1113 - RalfJung:vtable, r=RalfJung
add test for sketchy vtable Blocked on rust-lang/rust#67254
2 parents f94bc71 + bbd512d commit 60c7509

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
e862c01aadb2d029864f7bb256cf6c85bbb5d7e4
1+
12307b3b08edee543a78fb9d4a837fbd6d6ac0fa

tests/compile-fail/issue-miri-1112.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
trait Empty {}
2+
3+
#[repr(transparent)]
4+
pub struct FunnyPointer(dyn Empty);
5+
6+
#[repr(C)]
7+
pub struct Meta {
8+
drop_fn: fn(&mut ()),
9+
size: usize,
10+
align: usize,
11+
}
12+
13+
impl Meta {
14+
pub fn new() -> Self {
15+
Meta {
16+
drop_fn: |_| {},
17+
size: 0,
18+
align: 1,
19+
}
20+
}
21+
}
22+
23+
#[repr(C)]
24+
pub struct FatPointer {
25+
pub data: *const (),
26+
pub vtable: *const (),
27+
}
28+
29+
impl FunnyPointer {
30+
pub unsafe fn from_data_ptr(data: &String, ptr: *const Meta) -> &Self {
31+
let obj = FatPointer {
32+
data: data as *const _ as *const (),
33+
vtable: ptr as *const _ as *const (),
34+
};
35+
let obj = std::mem::transmute::<FatPointer, *mut FunnyPointer>(obj); //~ ERROR invalid drop fn in vtable
36+
&*obj
37+
}
38+
}
39+
40+
fn main() {
41+
unsafe {
42+
let meta = Meta::new();
43+
let hello = "hello".to_string();
44+
let _raw: &FunnyPointer = FunnyPointer::from_data_ptr(&hello, &meta as *const _);
45+
}
46+
}

0 commit comments

Comments
 (0)