-
Notifications
You must be signed in to change notification settings - Fork 343
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 #2195 - RalfJung:vtable-validation, r=RalfJung
test for Stacked Borrows error during vtable validation Fixes #2123 Needs rust-lang/rust#97761
- Loading branch information
Showing
5 changed files
with
53 additions
and
16 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 @@ | ||
09d52bc5d4260bac8b9a2ea8ac7a07c5c72906f1 | ||
99930ac7f8cbb5d9b319b2e2e92794fd6f24f556 |
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,19 @@ | ||
// error-pattern: vtable pointer does not have permission | ||
#![feature(ptr_metadata)] | ||
|
||
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) }) | ||
} | ||
|
||
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)); | ||
} | ||
} |
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,25 @@ | ||
error: Undefined Behavior: type validation failed: encountered vtable pointer does not have permission to read drop function pointer | ||
--> RUSTLIB/core/src/ptr/metadata.rs:LL:CC | ||
| | ||
LL | unsafe { PtrRepr { components: PtrComponents { data_address, metadata } }.const_ptr } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered vtable pointer does not have permission to read drop function pointer | ||
| | ||
= 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: inside `std::ptr::from_raw_parts::<dyn Foo>` at RUSTLIB/core/src/ptr/metadata.rs:LL:CC | ||
note: inside `uwu` at $DIR/vtable.rs:LL:CC | ||
--> $DIR/vtable.rs:LL:CC | ||
| | ||
LL | core::ptr::from_raw_parts(thin, unsafe { core::mem::transmute(meta) }) | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
note: inside `main` at $DIR/vtable.rs:LL:CC | ||
--> $DIR/vtable.rs:LL:CC | ||
| | ||
LL | let _ = uwu(ptr, core::mem::transmute(meta)); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace | ||
|
||
error: aborting due to previous error | ||
|