-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #2384 - RalfJung:vtables, r=RalfJung
adjust for symbolic vtables The Miri side of rust-lang/rust#99420
- Loading branch information
Showing
19 changed files
with
153 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
a7468c60f8dbf5feb23ad840b174d7e57113a846 | ||
e7a9c1141698bc4557b9da3d3fce2bf75339427f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
trait T1 { | ||
fn method1(self: Box<Self>); | ||
} | ||
trait T2 { | ||
fn method2(self: Box<Self>); | ||
} | ||
|
||
impl T1 for i32 { | ||
fn method1(self: Box<Self>) {} | ||
} | ||
|
||
fn main() { | ||
let r = Box::new(0) as Box<dyn T1>; | ||
let r2: Box<dyn T2> = unsafe { std::mem::transmute(r) }; | ||
r2.method2(); //~ERROR: call on a pointer whose vtable does not match its type | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error: Undefined Behavior: `dyn` call on a pointer whose vtable does not match its type | ||
--> $DIR/dyn-call-trait-mismatch.rs:LL:CC | ||
| | ||
LL | r2.method2(); | ||
| ^^^^^^^^^^^^ `dyn` call on a pointer whose vtable does not match its type | ||
| | ||
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior | ||
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information | ||
= note: backtrace: | ||
= note: inside `main` at $DIR/dyn-call-trait-mismatch.rs:LL:CC | ||
|
||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace | ||
|
||
error: aborting due to previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#![feature(trait_upcasting)] | ||
#![allow(incomplete_features)] | ||
|
||
trait Foo: PartialEq<i32> + std::fmt::Debug + Send + Sync { | ||
fn a(&self) -> i32 { | ||
10 | ||
} | ||
|
||
fn z(&self) -> i32 { | ||
11 | ||
} | ||
|
||
fn y(&self) -> i32 { | ||
12 | ||
} | ||
} | ||
|
||
trait Bar: Foo { | ||
fn b(&self) -> i32 { | ||
20 | ||
} | ||
|
||
fn w(&self) -> i32 { | ||
21 | ||
} | ||
} | ||
|
||
trait Baz: Bar { | ||
fn c(&self) -> i32 { | ||
30 | ||
} | ||
} | ||
|
||
impl Foo for i32 { | ||
fn a(&self) -> i32 { | ||
100 | ||
} | ||
} | ||
|
||
impl Bar for i32 { | ||
fn b(&self) -> i32 { | ||
200 | ||
} | ||
} | ||
|
||
impl Baz for i32 { | ||
fn c(&self) -> i32 { | ||
300 | ||
} | ||
} | ||
|
||
fn main() { | ||
let baz: &dyn Baz = &1; | ||
let _baz_fake: &dyn Bar = unsafe { std::mem::transmute(baz) }; | ||
//~^ERROR: upcast on a pointer whose vtable does not match its type | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error: Undefined Behavior: upcast on a pointer whose vtable does not match its type | ||
--> $DIR/dyn-upcast-trait-mismatch.rs:LL:CC | ||
| | ||
LL | let _baz_fake: &dyn Bar = unsafe { std::mem::transmute(baz) }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ upcast on a pointer whose vtable does not match its type | ||
| | ||
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior | ||
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information | ||
= note: backtrace: | ||
= note: inside `main` at $DIR/dyn-upcast-trait-mismatch.rs:LL:CC | ||
|
||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace | ||
|
||
error: aborting due to previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 6 additions & 4 deletions
10
tests/fail/stacked_borrows/vtable.rs → tests/pass/issues/issue-miri-2123.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,21 @@ | ||
//@error-pattern: vtable pointer does not have permission | ||
#![feature(ptr_metadata)] | ||
#![feature(ptr_metadata, layout_for_ptr)] | ||
|
||
use std::{mem, ptr}; | ||
|
||
trait Foo {} | ||
|
||
impl Foo for u32 {} | ||
|
||
fn uwu(thin: *const (), meta: &'static ()) -> *const dyn Foo { | ||
core::ptr::from_raw_parts(thin, unsafe { core::mem::transmute(meta) }) | ||
ptr::from_raw_parts(thin, unsafe { mem::transmute(meta) }) | ||
} | ||
|
||
fn main() { | ||
unsafe { | ||
let orig = 1_u32; | ||
let x = &orig as &dyn Foo; | ||
let (ptr, meta) = (x as *const dyn Foo).to_raw_parts(); | ||
let _ = uwu(ptr, core::mem::transmute(meta)); | ||
let ptr = uwu(ptr, mem::transmute(meta)); | ||
let _size = mem::size_of_val_raw(ptr); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters