test against passing invalid shared refs around

This commit is contained in:
Ralf Jung 2018-10-23 16:01:22 +02:00
parent 5388037f8a
commit 356369dd08
3 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,9 @@
// Make sure that we cannot load from memory a `&` that got already invalidated.
fn main() {
let x = &mut 42;
let xraw = x as *mut _;
let xref = unsafe { &*xraw };
let xref_in_mem = Box::new(xref);
let _val = *x; // invalidate xraw
let _val = *xref_in_mem; //~ ERROR Shr reference with non-reactivatable tag: Location should be frozen
}

View File

@ -0,0 +1,10 @@
// Make sure that we cannot pass by argument a `&` that got already invalidated.
fn foo(_: &i32) {}
fn main() {
let x = &mut 42;
let xraw = &*x as *const _;
let xref = unsafe { &*xraw };
let _val = *x; // invalidate xraw
foo(xref); //~ ERROR Shr reference with non-reactivatable tag: Location should be frozen
}

View File

@ -0,0 +1,11 @@
// Make sure that we cannot return a `&` that got already invalidated.
fn foo(x: &mut (i32, i32)) -> &i32 {
let xraw = x as *mut (i32, i32);
let ret = unsafe { &(*xraw).1 };
let _val = *x; // invalidate xraw and its children
ret //~ ERROR Shr reference with non-reactivatable tag: Location should be frozen
}
fn main() {
foo(&mut (1, 2));
}