ensure we allow zero-sized references to functions and vtables

This commit is contained in:
Ralf Jung 2023-08-04 14:50:45 +02:00
parent e55f49415d
commit f0cbc7d3dc
2 changed files with 32 additions and 0 deletions

View File

@ -248,6 +248,13 @@ fn tb_reborrow(
.insert(new_tag, protect);
}
let alloc_kind = this.get_alloc_info(alloc_id).2;
if !matches!(alloc_kind, AllocKind::LiveData) {
// There's not actually any bytes here where accesses could even be tracked.
// Just produce the new provenance, nothing else to do.
return Ok(Some(Provenance::Concrete { alloc_id, tag: new_tag }));
}
let span = this.machine.current_span();
let alloc_extra = this.get_alloc_extra(alloc_id)?;
let range = alloc_range(base_offset, ptr_size);

View File

@ -0,0 +1,25 @@
//@revisions: stack tree
//@[tree]compile-flags: -Zmiri-tree-borrows
// Create zero-sized references to vtables and function data.
// Just make sure nothing explodes.
use std::{mem, ptr};
fn check_ref(x: &()) {
let _ptr = ptr::addr_of!(*x);
}
fn main() {
check_ref({
// Create reference to a function.
let fnptr: fn(&()) = check_ref;
unsafe { mem::transmute(fnptr) }
});
check_ref({
// Create reference to a vtable.
let wideptr: &dyn Send = &0;
let fields: (&i32, &()) = unsafe { mem::transmute(wideptr) };
fields.1
})
}