Miri: more informative deallocation error messages
This commit is contained in:
parent
c2bc344eb2
commit
731113b8ee
1 changed files with 8 additions and 4 deletions
|
@ -285,9 +285,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
|
||||||
None => {
|
None => {
|
||||||
// Deallocating global memory -- always an error
|
// Deallocating global memory -- always an error
|
||||||
return Err(match self.tcx.get_global_alloc(ptr.alloc_id) {
|
return Err(match self.tcx.get_global_alloc(ptr.alloc_id) {
|
||||||
Some(GlobalAlloc::Function(..)) => err_ub_format!("deallocating a function"),
|
Some(GlobalAlloc::Function(..)) => {
|
||||||
|
err_ub_format!("deallocating {}, which is a function", ptr.alloc_id)
|
||||||
|
}
|
||||||
Some(GlobalAlloc::Static(..) | GlobalAlloc::Memory(..)) => {
|
Some(GlobalAlloc::Static(..) | GlobalAlloc::Memory(..)) => {
|
||||||
err_ub_format!("deallocating static memory")
|
err_ub_format!("deallocating {}, which is static memory", ptr.alloc_id)
|
||||||
}
|
}
|
||||||
None => err_ub!(PointerUseAfterFree(ptr.alloc_id)),
|
None => err_ub!(PointerUseAfterFree(ptr.alloc_id)),
|
||||||
}
|
}
|
||||||
|
@ -297,7 +299,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
|
||||||
|
|
||||||
if alloc_kind != kind {
|
if alloc_kind != kind {
|
||||||
throw_ub_format!(
|
throw_ub_format!(
|
||||||
"deallocating {} memory using {} deallocation operation",
|
"deallocating {}, which is {} memory, using {} deallocation operation",
|
||||||
|
ptr.alloc_id,
|
||||||
alloc_kind,
|
alloc_kind,
|
||||||
kind
|
kind
|
||||||
);
|
);
|
||||||
|
@ -305,7 +308,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
|
||||||
if let Some((size, align)) = old_size_and_align {
|
if let Some((size, align)) = old_size_and_align {
|
||||||
if size != alloc.size || align != alloc.align {
|
if size != alloc.size || align != alloc.align {
|
||||||
throw_ub_format!(
|
throw_ub_format!(
|
||||||
"incorrect layout on deallocation: allocation has size {} and alignment {}, but gave size {} and alignment {}",
|
"incorrect layout on deallocation: {} has size {} and alignment {}, but gave size {} and alignment {}",
|
||||||
|
ptr.alloc_id,
|
||||||
alloc.size.bytes(),
|
alloc.size.bytes(),
|
||||||
alloc.align.bytes(),
|
alloc.align.bytes(),
|
||||||
size.bytes(),
|
size.bytes(),
|
||||||
|
|
Loading…
Add table
Reference in a new issue