Skip to content

Commit c54dcf5

Browse files
committed
add some tests for retagging inside tuples and options
1 parent a1f895d commit c54dcf5

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed
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 `&mut` that got already invalidated, not even in an `Option`.
2+
fn foo(x: &mut (i32, i32)) -> Option<&mut i32> {
3+
let xraw = x as *mut (i32, i32);
4+
let ret = Some(unsafe { &mut (*xraw).1 });
5+
let _val = unsafe { *xraw }; // invalidate xref
6+
ret //~ ERROR does not exist on the stack
7+
}
8+
9+
fn main() {
10+
foo(&mut (1, 2));
11+
}
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 `&mut` that got already invalidated, not even in a tuple.
2+
fn foo(x: &mut (i32, i32)) -> (&mut i32,) {
3+
let xraw = x as *mut (i32, i32);
4+
let ret = (unsafe { &mut (*xraw).1 },);
5+
let _val = unsafe { *xraw }; // invalidate xref
6+
ret //~ ERROR does not exist on the stack
7+
}
8+
9+
fn main() {
10+
foo(&mut (1, 2));
11+
}
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, not even in an `Option`.
2+
fn foo(x: &mut (i32, i32)) -> Option<&i32> {
3+
let xraw = x as *mut (i32, i32);
4+
let ret = Some(unsafe { &(*xraw).1 });
5+
unsafe { *xraw = (42, 23) }; // unfreeze
6+
ret //~ ERROR is not frozen
7+
}
8+
9+
fn main() {
10+
foo(&mut (1, 2));
11+
}
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, not even in a tuple.
2+
fn foo(x: &mut (i32, i32)) -> (&i32,) {
3+
let xraw = x as *mut (i32, i32);
4+
let ret = (unsafe { &(*xraw).1 },);
5+
unsafe { *xraw = (42, 23) }; // unfreeze
6+
ret //~ ERROR is not frozen
7+
}
8+
9+
fn main() {
10+
foo(&mut (1, 2));
11+
}

0 commit comments

Comments
 (0)