Skip to content

Commit 356369d

Browse files
committed
test against passing invalid shared refs around
1 parent 5388037 commit 356369d

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Make sure that we cannot load from memory a `&` that got already invalidated.
2+
fn main() {
3+
let x = &mut 42;
4+
let xraw = x as *mut _;
5+
let xref = unsafe { &*xraw };
6+
let xref_in_mem = Box::new(xref);
7+
let _val = *x; // invalidate xraw
8+
let _val = *xref_in_mem; //~ ERROR Shr reference with non-reactivatable tag: Location should be frozen
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Make sure that we cannot pass by argument a `&` that got already invalidated.
2+
fn foo(_: &i32) {}
3+
4+
fn main() {
5+
let x = &mut 42;
6+
let xraw = &*x as *const _;
7+
let xref = unsafe { &*xraw };
8+
let _val = *x; // invalidate xraw
9+
foo(xref); //~ ERROR Shr reference with non-reactivatable tag: Location should be frozen
10+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Make sure that we cannot return a `&` that got already invalidated.
2+
fn foo(x: &mut (i32, i32)) -> &i32 {
3+
let xraw = x as *mut (i32, i32);
4+
let ret = unsafe { &(*xraw).1 };
5+
let _val = *x; // invalidate xraw and its children
6+
ret //~ ERROR Shr reference with non-reactivatable tag: Location should be frozen
7+
}
8+
9+
fn main() {
10+
foo(&mut (1, 2));
11+
}

0 commit comments

Comments
 (0)