add test for function pointer offsets
This commit is contained in:
parent
78aa93fa10
commit
6eafb10b87
11
tests/compile-fail/fn_ptr_offset.rs
Normal file
11
tests/compile-fail/fn_ptr_offset.rs
Normal file
@ -0,0 +1,11 @@
|
||||
use std::mem;
|
||||
|
||||
fn f() {}
|
||||
|
||||
fn main() {
|
||||
let x : fn() = f;
|
||||
let y : *mut u8 = unsafe { mem::transmute(x) };
|
||||
let y = y.wrapping_offset(1);
|
||||
let x : fn() = unsafe { mem::transmute(y) };
|
||||
x(); //~ ERROR: tried to use an integer pointer or a dangling pointer as a function pointer
|
||||
}
|
@ -42,7 +42,7 @@ unsafe extern fn dtor(mut ptr: *mut u64) {
|
||||
}
|
||||
|
||||
// Check if the records matches what we expect. If yes, clear the cannary.
|
||||
// If the record is wrong, the cannary will ever get cleared, leading to a leak -> test fails.
|
||||
// If the record is wrong, the cannary will never get cleared, leading to a leak -> test fails.
|
||||
// If the record is incomplete (i.e., more dtor calls happen), the check at the beginning of this function will fail -> test fails.
|
||||
// The correct sequence is: First key 0, then key 1, then key 0.
|
||||
if RECORD == 0_1_0 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user