add test for function pointer offsets

This commit is contained in:
Ralf Jung 2017-06-21 21:54:42 -07:00
parent 78aa93fa10
commit 6eafb10b87
2 changed files with 12 additions and 1 deletions

View 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
}

View File

@ -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 {